Runtime.exec

Discussion in 'Java' started by micro, Apr 18, 2007.

  1. micro

    micro Guest

    hi all,
    I use java in windows xp and I want to execute .jar files in my java
    program i tried the next code but it didn't work.
    no errors in compilation,and no exception when I run it ,yet my
    des.jar file didn't run.

    public class RunIt {
    public static void main(String args[]){
    String[] commands=new String[3];
    commands[0]="cmd.exe";
    commands[1]="cd C:\\Documents and Settings\\ASUS\\Desktop";
    commands[2]="java -jar des.jar";

    try {
    Runtime.getRuntime().exec(commands);

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

    although when I try: "java -jar des.jar" in the command line it works
    fine
     
    micro, Apr 18, 2007
    #1
    1. Advertising

  2. On 17 Apr 2007 22:09:28 -0700, micro wrote:
    > commands[0]="cmd.exe";
    > commands[1]="cd C:\\Documents and Settings\\ASUS\\Desktop";
    > commands[2]="java -jar des.jar";



    The command array you pass to Runtime.exec() should hold exactly *one*
    command, not a series of them.

    If you want to run the command from a specific directory, there is a
    version of Runtime.exec() that lets you specify a working directory.

    /gordon

    --
     
    Gordon Beaton, Apr 18, 2007
    #2
    1. Advertising

  3. micro

    micro Guest

    On Apr 18, 9:03 am, Gordon Beaton <> wrote:
    > On 17 Apr 2007 22:09:28 -0700, micro wrote:


    > The command array you pass to Runtime.exec() should hold exactly *one*
    > command, not a series of them.
    >
    > If you want to run the command from a specific directory, there is a
    > version of Runtime.exec() that lets you specify a working directory.
    >
    > /gordon
    >
    > --

    thank a lot for your valuable help.
    solved
    Process p=Runtime.getRuntime().exec("java -jar des.jar",null,new
    File("C:\\Documents and Settings\\ASUS\\Desktop"));
     
    micro, Apr 18, 2007
    #3
    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. Hal Vaughan
    Replies:
    11
    Views:
    1,154
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,122
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    478
    Duncan Booth
    Jul 22, 2004
  4. Guillermo Riojas
    Replies:
    0
    Views:
    184
    Guillermo Riojas
    Nov 26, 2010
  5. Random Task
    Replies:
    12
    Views:
    671
    Joe Smith
    Dec 4, 2005
Loading...

Share This Page