File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes spawning cmd scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "spawning cmd scripts" Watch "spawning cmd scripts" New topic

spawning cmd scripts

Aaron Ehrensberger

Joined: Jun 22, 2004
Posts: 7
I'm spawning a .cmd script from within my main java app. Inside that script, it's setting up some values, then trying to spawn another java program. I don't believe that the 2nd java program is executing or returning to the calling script and then the 1st script hangs.

The code to call the initial script....

Process p = Runtime.getRuntime().exec(updateFile);

// Create threads to read the output and error streams.
OutputWriter errorWriter= new OutputWriter(p.getErrorStream(), "ERROR");
OutputWriter outputWriter = new OutputWriter(p.getInputStream(), "OUTPUT");
// Start the threads.

result = p.waitFor();

This code calls a script that contains a line ...

cd /D %LEADERBOARD_HOME%\server\leaderboard\deploy\Leaderboard.ear

java -classpath %classpath% com.smg.common.utils.MSSQLDSFileEditor %LEADERBOARD_HOME%\server\leaderboard\deploy %RegValue2% %RegValue3% %RegValue4%

Calling this script directly from a command prompt works fine, so I know that the script is working, but somewhere when java calls the script to call java, I'm missing something.

Is this possible? What am I missing?

[ October 25, 2004: Message edited by: Aaron Ehrensberger ]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Perhaps your script doesn't know the variables, like '%LEADERBOARD_HOME%'. ?
They aren't 'inherited' from the environment automatically.
I agree. Here's the link:
subject: spawning cmd scripts
It's not a secret anymore!