On Aug 13, 2:17 pm, Danger_Duck <ganggang3s...@gmail.com> wrote:
So I have a method that includes a few lines that will create a batch
file and run it using Java.lang.Process, but lately I've gotten a
mysterious return value:
Process proc = Runtime.getRuntime().exec(binDirectory + "temp.bat");
Wait, wait, hold on.
Runtime.exec *does not* invoke a command processor. It's a wrapper
around CreateProcessEx (on Windows) or fork+exec (on *nix), not around
system(). So you can't just blithely pass it a script unless the
underlying process creation primtives know how to cope. In the case
of CreateProcessEx, it *cannot* launch batch files - it needs a
command interpreter to do that.
You want to run the following:
exec ("cmd", "/C", binDirectory + "temp.bat");
(NOT "cmd /C " + binDirectory + "temp.bat", as this will blow up if
binDirectory contains spaces.)
Of course, Things Are Different on *nix - there's no cmd command, and
exec() can usually cope with scripts just fine. This is one of the
many ways using native tools can completely torpedo portability in
May be unrelated to the issue I'm trying to solve where for some
reason I cannot call a constructor in my class
(NoClassDefFoundError), but I'm curious as to what this means.
The Sun Javadoc only tells me that 0 is the normal value while a
google search is most unhelpful. I'm ever-hopeful that someone here
can explain what's going on.
Even that's only a convention. The return code from
Process.exitValue() dictated entirely by the newly created process;
zero-means-success is a common convention but is by no means required.