https://bz.apache.org/bugzilla/show_bug.cgi?id=26453

--- Comment #2 from Chris Fairman <chris.fair...@ballaerospace.com> ---
Ultimately the issue is that if a non-zero return value is encountered (even
when expected) it isn't possible to avoid the following output even when
"discardOutput" and/or "discardError" is set:
        [exec] Result: 1
                - or -
        [exec] Result: <Other Non-Zero Return Value>

As use case for expected non-zero return values on Windows, findstr returns 0
if a string is found, non-zero if not.

        We use a for loop to check the state of a TomEE service that can take a
while to stop:
                <exec executable="cmd" spawn="false" failonerror="false"
resultproperty="result" discardError="true" >
                        <arg value="/c" />
                        <arg value="sc query ${service_name} | findstr STATE |
findstr STOPPED"/> 
                </exec>

        If a service is not in a stopped state yet ( i.e: STOPPING ), ${result}
is populated as expected, however "[exec] Result: 1" is displayed despite
efforts to avoid output.

test.xml:
<?xml version="1.0"?>
<project name="Exec_Testing" default="all" basedir=".">

        <target name="return_zero" >
                <exec executable="cmd" spawn="false" failonerror="false"
resultproperty="result" discardOutput="true" discardError="true" >
                        <arg value="/c" />
                        <arg value="exit 0"/> 
                </exec>
        </target>

        <target name="return_nonzero" >
                <exec executable="cmd" spawn="false" failonerror="false"
resultproperty="result" discardOutput="true" discardError="true" >
                        <arg value="/c" />
                        <arg value="exit 1"/> 
                </exec>
        </target>

</project>


---------------
Return Zero
---------------
F:\> ant -buildfile test.xml return_zero
Buildfile: F:\test.xml

return_zero:

BUILD SUCCESSFUL
Total time: 0 seconds


---------------
Return NonZero
---------------
F:\> ant -buildfile test.xml return_nonzero
Buildfile: F:\test.xml

return_nonzero:
     [exec] Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to