import java.io.*;
class RunProc {
public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c dir");
InputStream inStd = pr.getInputStream();
InputStreamReader inStdR = new InputStreamReader(inStd);
BufferedReader bStd = new BufferedReader(inStdR);
String line=null;
while((line=bStd.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
December 18, 2007
Java Runtime Exec Example
3:09 AM
No comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment