Problem in run system command within Java using Runtime.exec()

C

Charlie Zhang

Want to call a simulator within Java using Runtime.exec(), but never succeed.
I can call the simulator in command line like:
C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile

Part of the code is:

Sting[] cmd = new String[3];
cmd[0] = "command.com";
cmd[1] = "/C";
cmd[2] ="C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile";
Runtime.getRuntime.exec(cmd);

Have spent several days on this bug, can anyone here help me?

Thanks in advance!
 
C

Chris Smith

Charlie said:
Want to call a simulator within Java using Runtime.exec(), but never succeed.
I can call the simulator in command line like:
C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile

Are you sure? Perhaps you mean for those to be backslashes. The
Windows kernel doesn't distinguish between a forward or backward slash,
but the command interpreter does. Try:
cmd[2] ="C:\\SimuDirctory\\Simulator -q C:\\SimuDirectory\\SimuFile";

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Charle

Thanks, Chris!
I tried
cmd[2] ="C:\\SimuDirctory\\Simulator -q C:\\SimuDirectory\\SimuFile";
but it still did not work, instead, when I tried
cmd[2] ="C:\\SimuDirctory\\Simulator";
Java did launch the simulator. And I aim at launch the simulator and
let it begin one specific simulation. Can Runtime.exec() do this?

Regards,

Charlie



Chris Smith said:
Charlie said:
Want to call a simulator within Java using Runtime.exec(), but never succeed.
I can call the simulator in command line like:
C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile

Are you sure? Perhaps you mean for those to be backslashes. The
Windows kernel doesn't distinguish between a forward or backward slash,
but the command interpreter does. Try:
cmd[2] ="C:\\SimuDirctory\\Simulator -q C:\\SimuDirectory\\SimuFile";
 
S

Sudsy

Charlie said:
Want to call a simulator within Java using Runtime.exec(), but never succeed.
I can call the simulator in command line like:
C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile

Part of the code is:

Sting[] cmd = new String[3];
cmd[0] = "command.com";
cmd[1] = "/C";
cmd[2] ="C:/SimuDirctory/Simulator -q C:/SimuDirectory/SimuFile";
Runtime.getRuntime.exec(cmd);

Try this:

String[] cmd = new String[5];
cmd[0] = "command.com";
cmd[1] = "/C";
cmd[2] = "C:\\SimuDirectory\\Simulator";
cmd[3] = "-q";
cmd[4] = "C:\\SimuDirectory\\SimuFile";
Runtime.getRuntime().exec( cmd );
 
C

Chris Smith

Charle said:
I tried
cmd[2] ="C:\\SimuDirctory\\Simulator -q C:\\SimuDirectory\\SimuFile";
but it still did not work, instead, when I tried
cmd[2] ="C:\\SimuDirctory\\Simulator";
Java did launch the simulator. And I aim at launch the simulator and
let it begin one specific simulation. Can Runtime.exec() do this?

I don't see a good reason that Runtime.exec couldn't do it. Perhaps
it's because (if the above code is really a true copy) you call the
directory "SimuDirctory" in the first case, but "SimuDirectory" in the
second.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Q

Québec

http://www.javaworld.com/jw-12-2000/traps/jw-1229-traps.zip


Chris Smith said:
Charle said:
I tried
cmd[2] ="C:\\SimuDirctory\\Simulator -q C:\\SimuDirectory\\SimuFile";
but it still did not work, instead, when I tried
cmd[2] ="C:\\SimuDirctory\\Simulator";
Java did launch the simulator. And I aim at launch the simulator and
let it begin one specific simulation. Can Runtime.exec() do this?

I don't see a good reason that Runtime.exec couldn't do it. Perhaps
it's because (if the above code is really a true copy) you call the
directory "SimuDirctory" in the first case, but "SimuDirectory" in the
second.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top