wood burning stoves 2.0*
The moose likes Java in General and the fly likes running exe from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "running exe from java" Watch "running exe from java" New topic

running exe from java

jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
I use Runtime.exec to execute an exe, normally when this exe runs under dos command it runs rather quickly. However running it from java seems to slow it down considerably(maybe 100x). I am wondering if this is because java allocates limited resources to run the exe. If so what's the solution to make it run quicker.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
If I am not wrong, then when you run any application via java, JVM / JRE also comes in the picture. Hence it doesn't run as fast as it runs directly.

My blood is tested +ve for Java.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41114
The executable is presumably native code, so its execution is not influenced by Java memory constraints or JVM speed - it's its own process with its own memory. How do your measure the speed?

Ping & DNS - my free Android networking tools app
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I guess what Ulf Dittmer saying is right.

It should not be make any difference.

I believe, if you run application from Java, it may take more time to startup compare to the directly startup. But it should not slowdown overall performance.
[ September 30, 2005: Message edited by: Chetan Parekh ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Are you reading the output streams from the process? I wonder if the exe could hang trying to write stdout or errout. Some won't run at all if you're not reading the streams.

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
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
I am reading the standard outputstream and output error stream. The exe writes to a status file once every second to indicate how much has been done. that's how I know that the exe process slowed down not just by the startup time but actually along the way.
The exe took 10 secs when running from the dos cmd, and took 100 secs when running from java. If jvm does not put any memory/resource constraint on the native process it spawned, then i am guessing that by reading from standard output and standard error, the java app interfered when the normal native execution?
thanks for any helpful advise
It is sorta covered in the JavaRanch Style Guide.
subject: running exe from java
Similar Threads
As a command it runs fine from cmd prompt but not from java code
Running a .exe from java program
Applet runs in eclipse, but when I embed it in html, it doesnt work
Launching an .exe as a different user
Native Compiler for Java