on 10-26-2006 1:35 PM
hi i am using this code to execute os command
import java.io.File;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RunSystemCommand {
public static void main(String args[]) {
String s = null;
// system command to run
String cmd = "copy a.txt b.txt";
// set the working directory for the OS command processor
File workDir = new File("c:
temp");
try {
Process p = Runtime.getRuntime().exec(cmd, null, workDir);
int i = p.waitFor();
if (i == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
}
else {
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((s = stdErr.readLine()) != null) {
System.out.println(s);
}
}
}
catch (Exception e) {
System.out.println(e);
}
}
}
it doesnt work,the error is
java.io.IOException: CreateProcess: copy a.txt b.txt error=2
thx,Shai
Hi, Shai!
The error 2 comes from the CreateProcess() call from Windows GetLastError(): 2 - "The system cannot find the file specified. - ERROR_FILE_NOT_FOUND". Check the filepath!
Regards,
Thomas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.