Runtime.exec

M

micro

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
 
G

Gordon Beaton

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

--
 
M

micro

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"));
 

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,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top