This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
mike nu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it windows or Unix?
 
mike nu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's suppose to work cross platforms, so both Windows and Unix.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maximum intermediate question.

Did you try:

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

And did you think of
 
mike nu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe you should try Runtime.exec that takes a String[]as parameter ,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!