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
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.
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
java process - Google Search
Process (Java 2 Platform SE v1.4.2)
I reckon you'll quickly spot the required method.
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?
Oh. I was looking at the 'exitValue()' method!the waitFor 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.
twk (September 2nd, 2011)