dcsimg
Passing a command to the cmd.exe and executing it
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Subramanian_chidambaram
Posted On:   Monday, April 9, 2001 04:09 AM

I have the following code.But it doesnt seem to work. import java.io.*; public class Console { public Console() { } public static void main(String[] args) { try{ Runtime r = Runtime.getRuntime(); String cmdarray[] = {"cmd.exe","D:\boston\scheduling\shutdown1.cmd"}; Process p = r.exec(cmdarray); System.out.println("process is started"); } catch (Exception e) { System.out.println("Inside the exception"); e.printStackTrace(); } } } The process it seems cannot open command prompt and pass the command.But the same is not the case with notepad.    More>>

I have the following code.But it doesnt seem to work.

import java.io.*;

public class Console {



public Console() {

}

public static void main(String[] args) {
try{
Runtime r = Runtime.getRuntime();
String cmdarray[] = {"cmd.exe","D:\boston\scheduling\shutdown1.cmd"};
Process p = r.exec(cmdarray);

System.out.println("process is started");
}
catch (Exception e) {
System.out.println("Inside the exception");
e.printStackTrace();
}
}
}

The process it seems cannot open command prompt and pass the command.But the same is not the case with notepad.
if i call the notepad.exe instead of cmd.exe it actually opens the file in that particular directory.

   <<Less

Re: Passing a command to the cmd.exe and executing it

Posted By:   Marcos_Nava  
Posted On:   Thursday, June 7, 2001 12:51 PM

Try to use
"cmd.exe /c"

It worked for me.
About | Sitemap | Contact