07 October 2012

code to execute .exe in java

import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;


public class test {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {

Process pp=run.exec("progs");    // for cmd commands use=> run.exec("cmd /c dir");  where dir is a command. another eg=>run.exec("cmd /c javac x.java")
BufferedReader in =new BufferedReader(new InputStreamReader(pp.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}


//run.exec("cmd /c start");  for opening cmd




Delicious add to del.icio.us saved by 0 users

No comments:

Post a Comment