Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Runtime.exec

Reply
Thread Tools

Runtime.exec

 
 
micro
Guest
Posts: n/a
 
      04-18-2007
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      04-18-2007
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

--
 
Reply With Quote
 
 
 
 
micro
Guest
Posts: n/a
 
      04-18-2007
On Apr 18, 9:03 am, Gordon Beaton <(E-Mail Removed)> 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"));

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments