Hi folks,
this works as expected - you start an external application and this
application returns an exit value.
Under many OS an non-zero exit value is considered as an error code
hence commons-exec throws an exception (please note that the "good" exit
values are OS-specific). So in your use case the behavior is perfectly
reasonable since "ping NOEXISTINGHOST" does indeed not work properly. If
you would like to consider certain exit values as success than checkout
"DefaultExecutor#setExitValue()"
Cheers,
Siegfried Goeschl
On 07.11.12 08:38, Yi Huang wrote:
I did not use exec for a while but from what I remember, you had better set
the default exit value. For example, if default exit value is set to 1,
then exec will return 1 if it think the command is ok. Then your system
will say there is an error because the system exit value 1 is an error
while 0 is normal.
Hope that helps somehow.
--Yi Huang
2012/11/7 nie fei <[email protected]>
I'm a new learner for this API. Sorry for the last mail, my mistake with
wrong button.
CommandLine cmdLine = CommandLine.parse("ping 10.80.41.171 -n 1");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DefaultExecutor exec = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(
outputStream);
exec.setStreamHandler(streamHandler);
exec.execute(cmdLine);
System.out.println(outputStream.toString());
Normally, if the address is available, then there will be no exception
raised. Otherwise, the exec.execute(cmdLine) will raise exception:
Process exited with an error: 1 (Exit value: 1)
Is it normal? Can anyone explain why?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]