wood burning stoves*
The moose likes Beginning Java and the fly likes cant  use exec() method to run  java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cant  use exec() method to run  java file" Watch "cant  use exec() method to run  java file" New topic
Author

cant use exec() method to run java file

mohan dodderi
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
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

Joined: Aug 03, 2002
Posts: 7729
Moving to Java In General (Beginner)...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant use exec() method to run java file