• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

exec command cd then command java

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!!
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
a wee bit from the empire
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic