Problem with Runtime.exec()

I will have to execute IReports tool in click of a button. I wrote the following lines in button's actionPerformed:

Process p=Runtime.getRuntime().exec("C:/iReport/iReport.exe");

I have iReport.exe in a folder iReport in c:/;Its not opening and giving me a JavaVirtualMachineLauncher dialog box with this message "Couldnot find Main Class.Program will exit"...I tried with other exe like:notepad.exe and explorer.exe; Is there anything that i should add or do?

[480 byte] By [Sruthi.ma] at [2007-10-3 8:56:54]
# 1
Check http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.htmlBut I guess that in fact you cannot even run your program, it's not the code in it.Mike
bellyrippera at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 2
Can you open it from the command line?
paulcwa at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 3
yes..From command promt iam able to execute it.
Sruthi.ma at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 4
have you tried windows slashes instead of unix slashes? be sure to escape them.%
duffymoa at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 5
like this:Process p=Runtime.getRuntime().exec("C:\\iReport\\iReport.exe");
duffymoa at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 6
Now i tried it ..but not working...Is it true that ...you cant execute processes written in java thru runtime.exec() method..and if you want to run them you should create an object of their main class file in your method ....
Sruthi.ma at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 7

> Now i tried it ..but not working...

> Is it true that

> ...you cant execute processes written in java thru

> runtime.exec() method..

No.

> and if you want to run them

> you should create an object of their main class file

> in your method ....

It's generally better to use the classes than to start up another JVM process. But rather than use the main class, it's even better to use the classes as an API. IMO anyway.

By the way, you're overusing ellipses.

paulcwa at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 8
I've read throught the thread, and I'm still not sure wether or not your program is actually running. Let's at least start with that. Does your window open when you run the program?
AFlooda at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 9

Mr.paulcw,

i am working on -using API.

Mr.AFlood,

My window opens when I run the program.Then I click on the button and a dialog box appears with message "Couldnot find Main Class.Program will exit".The path of the exe file is correct and I can execute it from command promt. This is the status.

Sruthi.ma at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...
# 10

Apparently the .exe finds and invokes the right class, somehow, and apparently that mechanism is broken when invoked with Runtime.exec. My feeling is that if this is the case, then the .exe is **** and should be avoided anyway. And so you should use the API of the code, if available.

Otherwise...does the .exe expect any environment variables to be set? Maybe that's the problem.

paulcwa at 2007-7-15 4:07:14 > top of Java-index,Java Essentials,Java Programming...