Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java.lang.Process exitValue == 2

6,456 views
Skip to first unread message

Annette Strupp-Adams

unread,
May 4, 1998, 3:00:00 AM5/4/98
to

Hello,

when I am trying to run the foll. Unix command from a Java application,
I get an
exitValue of 2. Can anyone tell me where to find out what the 2 means
?

Here is the code:

try{
String command[] = {"/usr/sbin/link", "/mydir/myfile.txt",
/mydir/otherdir/myfile.txt"};

Process p = Runtime.getRuntime().exec( command );
p.waitFor();
System.out.println("return code: " + p.exitValue());
}

I get a return code of 2 if I try to execute a cp or a link command.
Any suggestions
are appreciated.

Thanks,

Annette


--
Annette Strupp-Adams
Senior Systems Analyst/Internet Developer
ast...@nlm.nih.gov
National Library of Medicine


Andreas Rammelt

unread,
May 5, 1998, 3:00:00 AM5/5/98
to Annette Strupp-Adams

The 2 means that the command has failed to execute for some reason
(possibly a wrong path). You can get the error code by using the error
stream of the Process. Insert the following code after the p.waitFor()
line to see what happened:

int len;
if ((len = p.getErrorStream().available()) > 0) {
byte[] buf = new byte[len];
p.getErrorStream().read(buf);
System.err.println("Command error:\t\""+new String(buf)+"\"");
}

Regards
Rammi
--
<mailto:ra...@lineas.de> -- work
<mailto:ra...@quincunx.escape.de> -- private
<http://www.escape.de/user/quincunx/> -- homepage (uses Java applet)
Get the famous DXF Viewer Applet from:
<http://www.escape.de/user/quincunx/viewer_intro.html>

"Reality is a fake"

0 new messages