Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it windows or Unix?
 
mike nu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's suppose to work cross platforms, so both Windows and Unix.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe you should try Runtime.exec that takes a String[]as parameter ,
 
reply
    Bookmark Topic Watch Topic
  • New Topic