Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cant use exec() method to run java file

 
mohan dodderi
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello , i am trying to execute a java file using runtime.exec("java filename"); command in my programme but it is not working.
i tried with -classpath option also still it is not working.pls if u know tell me why it is not executing the statement.

thanks and regards
Mohandodderi
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner)...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're in JDK 5 look into ProcessBuilder. This supercedes exec() and lets you set environment variables and working directory before you start your process. It might help to set up classpath and path and such before you run your program.

If you can tolerate an OS-dependent technique I usually start my Java programs from very short batch or script files that set up the same things - current directory, path, classpath, etc. You could launch the script instead of java.exe.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mohan dodderi:
hello , i am trying to execute a java file using runtime.exec("java filename"); command in my programme but it is not working.
i tried with -classpath option also still it is not working.pls if u know tell me why it is not executing the statement.

thanks and regards
Mohandodderi


What do you mean by "it's not working"? Does your program compile? If not, what compiler errors do you get? If it does, what happens when you run it? Do you get a run-time error message (i.e. an exception)? If so, please post the full error message. If not, how does the behavior differ from what you expect? In order for us to help you, you need to provide more details.

Thanks,

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic