Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Exit Status from Perl program called by java using runtime

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Exit Status from Perl program called by java using runtime

    How do I get the exit status returned by a perl script called from a java program using runtime. the perl script can exit with several exit status's and I need to know what that value is to know what to do after the return.

    thanks,
    twk


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Exit Status from Perl program called by java using runtime

    java process - Google Search
    Process (Java 2 Platform SE v1.4.2)
    I reckon you'll quickly spot the required method.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Exit Status from Perl program called by java using runtime

    yup, it would appear the waitFor method gives me what I need but I also noted that in the description it says that "The Runtime.exec methods may not work well for ... or shell scripts. ". I expect shell script may include perl scripts as well. Is there an alternative way to execute unix script that is more suited to the task?

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Exit Status from Perl program called by java using runtime

    the waitFor method
    Oh. I was looking at the 'exitValue()' method!
    You will need to use 'waitFor' for anything but the most trivial scripts if you want any values back from them, though I was working on something recently that read both the output and the error streams from a Process and waited for the Process to close the streams before reading the exitValue(). Looking again, I see I use both waitFor() and exitValue() after the streams have closed. Damn... redundant code. It's in production, so I'll add a //TODO.

    I don't know why the API docs warn "or shell scripts" - perhaps it's intended to include some of those funny console utilities that don't always themselves work well when run without a terminal? I use ProcessBuilder a lot for shell scripts that use 3rd party tools which run deterministically, get all their input from the command line arguments, reliably write errors and output and then exit successfully or with an error code. I've never had a problem with any of them. I guess as long as you're sensible about what you're trying to run, you'll have the same experience too.

  5. The Following User Says Thank You to Sean4u For This Useful Post:

    twk (September 2nd, 2011)

Similar Threads

  1. In eclipse how do you get the runtime of your program?
    By beginnerprogrammer in forum Java Theory & Questions
    Replies: 5
    Last Post: May 22nd, 2011, 04:19 PM
  2. Can't seem to understand why my while loop doesn't exit!
    By vortexnl in forum Loops & Control Statements
    Replies: 6
    Last Post: February 11th, 2011, 03:43 PM
  3. Jar self delete on exit?
    By KiwiProg in forum Java Theory & Questions
    Replies: 1
    Last Post: December 19th, 2010, 02:54 AM
  4. Replies: 0
    Last Post: February 22nd, 2010, 01:21 AM
  5. Need java code to know the browser status
    By newnewgen in forum Java Theory & Questions
    Replies: 2
    Last Post: January 8th, 2010, 11:39 PM