This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes using Runtime.exec() and the process exitValue = 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "using Runtime.exec() and the process exitValue = 1" Watch "using Runtime.exec() and the process exitValue = 1" New topic
Author

using Runtime.exec() and the process exitValue = 1

mike nu
Ranch Hand

Joined: Mar 11, 2001
Posts: 63
Hi there,

I am trying to use the Runtime.exec() to call another Java program, like this way:

Runtime runtime = Runtime.getRuntime();
Process process = null;

try{
process = runtime.exec("java mypackage.MyProgram");
}catch(Throwable t){
t.printStackTrace();
}
......

process.waitFor();
int exitValue = process.exitValue();

But MyProgram does not get executed, and the exitValue = 1

Can anyone tell me what does the exitValue = 1 mean? What's wrong with my code?

Thanks a lot.

Mike
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
Is it windows or Unix?
mike nu
Ranch Hand

Joined: Mar 11, 2001
Posts: 63
It's suppose to work cross platforms, so both Windows and Unix.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

maximum intermediate question.

Did you try:

which only solves finding the jdk, not the mypackage-location.

And did you think of


http://home.arcor.de/hirnstrom/bewerbung
mike nu
Ranch Hand

Joined: Mar 11, 2001
Posts: 63
Now I know that the return code of Process.exitValue() = 1, means that can not find the class.

Now the actuall error is:

java.lang.NoClassDefFoundError: my/pkg/MyProgram

MyProgram is in the same package of the parent process. Is there any trick in specifying the subprocess classpath?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

MyProgram is in the same package of the parent process. Is there any trick in specifying the subprocess classpath?

But it will not extend the environment (path, classpath, systemvariables) of the parent process!
There is no trick in specifying the classpath of the subprocess - only the common technique to specify it.
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
maybe you should try Runtime.exec that takes a String[]as parameter ,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using Runtime.exec() and the process exitValue = 1
 
Similar Threads
How to ensure a file is written completely.
Why is not the process terminating after executing the command
Controlling Windows Services from a Java App
Run time exec problem
qshell script execute on Java PGM