Results 1 to 2 of 2
  1. #1
    Boomn4x4 is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Getting exit code of process

    When running a command from a command line:
    Java Code:
    /home/me/bin/command
    then checking the exit code
    Java Code:
    echo $?
    I get the desired result

    However, when I do it from java
    Java Code:
    Runtime run = Runtime.getRuntime();
    		try{
    			p = run.exec("/home/me/bin/command");
    			rc = p.waitFor();
    			System.out.println(rc);
    			
    		}
    I always get an exit code of 255.

    What am I doing wrong?

  2. #2
    Boomn4x4 is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Re: Getting exit code of process

    The problem ended up being that the command I was calling was calling another command that wasn't in the standard PATH environement so the command was failing to run (I figured this out by redirecting standard output to displaying to screen and the output made it clear it was failing). To resolve, I had to use the overrloaded method exec(command, environtment, root dir) and supply PATH=/home/user/bin to the environment parameter.

Similar Threads

  1. exit code for JApplet
    By tnixon22 in forum New To Java
    Replies: 1
    Last Post: 02-25-2011, 05:56 AM
  2. How to run and exit a process
    By cracker in forum New To Java
    Replies: 2
    Last Post: 02-15-2011, 04:11 PM
  3. shell exit code
    By mac in forum New To Java
    Replies: 2
    Last Post: 05-18-2010, 12:58 AM
  4. Process exit value = 128
    By trivektor in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-19-2008, 09:11 AM
  5. JVM terminated Exit code=1
    By oregon in forum Eclipse
    Replies: 3
    Last Post: 09-29-2008, 10:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •