• Post Reply Bookmark Topic Watch Topic
  • New Topic

exec command cd then command java  RSS feed

 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
i dont'succeed in doing the command "cd" then doing the command "java".
Indeed this code doesn't work (it makes nothing):
try{
Process p1 = Runtime.getRuntime().exec("cd "+rep);

try{
p1.waitFor();
}
}
catch(InterruptedException ire){}

Process p2 = Runtime.getRuntime().exec("java "+nameOfProg);
try{
p2.waitFor();
}
catch(InterruptedException ire){}
catch(IOException ioe){}
I have vefified tyhe command of cd and the command of java and they work when i'm in the console
Help please !!!
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I think you are missing is that each command is invoked in a separate context. So: A context is created. Then the "cd" changes the current working directory for the first context. Then the first context is discarded. Then a new context is created. Then the "java" command is run in the new context.
You could try putting a command separator ";" between the commands, and running them in the same context :-

Let us know if that works.
[ June 11, 2002: Message edited by: Frank Carver ]
 
Laojar Chuger
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you've got from the test. In a previous project I tried to create a java demon process that invoke tests at specific times and stop/start certain java process. The result was I could not start a new java process by 1). Get runtiome. 2). Invoke a script from runtime. 3). Start new java process from the script.
Later I gave up this attempt as every java process needs a JVM instance. What I tried was acctually try to creat a JVM inside another JVM. So nice to know your test result.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!