Exit Value = 35584 from Java.lang.Process

D

Danger_Duck

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");
proc.waitFor();
System.out.println("Exit value = " + proc.exitValue());

--> Gives me 35584 instead of 0 here.

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.

Thanks!
 
M

Mark Space

Danger_Duck said:
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");
proc.waitFor();
System.out.println("Exit value = " + proc.exitValue());

--> Gives me 35584 instead of 0 here.

I don't know, specifically, but it's important to read the manual here:

"The methods that create processes may not work well for special
processes on certain native platforms, such as native windowing
processes, daemon processes, Win16/DOS processes on Microsoft Windows,
or shell scripts. "

In other words, all bets are off. Sun does not say that this will
actually work.

<https://java.sun.com/javase/6/docs/api/java/lang/Process.html>
 
R

RedGrittyBrick

Danger_Duck said:
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");
proc.waitFor();
System.out.println("Exit value = " + proc.exitValue());

--> Gives me 35584 instead of 0 here.

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.

Something in temp.bat exited with error code 139?
(35584 >> 8 == 1139)
 
O

Owen Jacobson

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
Java...
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.

-o
 
D

Danger_Duck

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
Java...


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.

-o

Exit Value issue resolved-it's returning 0 once again:
All I did was rebuild the project which recreated an executable which
the batch file was executing.

TheNoClassDefError is unrelated to the exit value and just happened to
coincidentally appear the same time. I'm still working on it, but it
has something to do with trouble accessing external classes for a .jar
I put into eclipse....yeah total tangent.

So anyway, for anyone curious, someone informed me that:
"abnormal exit: exit code=35584 typically implies problems in the
path to the executable or the path to something required by the
executable."
 
D

Danger_Duck

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
Java...


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.

-o

Uh, I guess the code I gave was incomplete since I was only wondering
about the exit value-here is more of it-and it runs batch files just
fine ;)

File f = new File(binDirectory + "temp.bat");
PrintWriter p;
try {
p = new PrintWriter(f);
p.println(binDirectory + "\\" + binName + " " + binDirectory + "\\"
+ csvName);
p.close();
Process proc = Runtime.getRuntime().exec(binDirectory +
"temp.bat");
proc.waitFor();
System.out.println("Exit value = " + proc.exitValue());
} catch (FileNotFoundException e) {
 
R

Roedy Green

System.out.println("Exit value = " + proc.exitValue());

--> Gives me 35584 instead of 0 here.

That value came from the spawned program, right? 35584 or 0x8b00. If
you scan that program , or read its docs, you may find what it means.
That is its return code.
 
A

Arne Vajhøj

Roedy said:
That value came from the spawned program, right? 35584 or 0x8b00. If
you scan that program , or read its docs, you may find what it means.
That is its return code.

It is not a particular well known error code.

Another possibility is that the program is not setting
the return code and there return whatever random data
that was in the register where the return code should
have been stored.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top