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

Discussion in 'Java' started by Charlie Zhang, Jun 17, 2004.

  1. 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!
    Charlie Zhang, Jun 17, 2004
    #1
    1. Advertising

  2. Charlie Zhang

    Chris Smith Guest

    Charlie Zhang wrote:
    > 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
    Chris Smith, Jun 17, 2004
    #2
    1. Advertising

  3. Charlie Zhang

    Charle Guest

    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 <> wrote in message news:<4.net>...
    > Charlie Zhang wrote:
    > > 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";
    Charle, Jun 18, 2004
    #3
  4. Charlie Zhang

    Sudsy Guest

    Charlie Zhang wrote:
    > 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 );
    Sudsy, Jun 18, 2004
    #4
  5. Charlie Zhang

    Chris Smith Guest

    Charle wrote:
    > 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
    Chris Smith, Jun 18, 2004
    #5
  6. Charlie Zhang

    Québec Guest

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


    "Chris Smith" <> a écrit dans le message de
    news:4.net...
    > Charle wrote:
    > > 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
    Québec, Jun 19, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leszek Dubiel
    Replies:
    3
    Views:
    9,782
  2. Dave Neuendorf
    Replies:
    5
    Views:
    6,705
    Anthony Borla
    Feb 25, 2005
  3. Hal Vaughan
    Replies:
    11
    Views:
    1,090
    Gordon Beaton
    May 22, 2006
  4. Replies:
    4
    Views:
    2,908
    Robert Mark Bram
    Oct 31, 2006
  5. Random Task
    Replies:
    12
    Views:
    633
    Joe Smith
    Dec 4, 2005
Loading...

Share This Page