public class TestCom {
public static void main(String[] args) {
String[] cmd = new String[]{"/bin/sh", "-c", "ls"};
TestCom tt = new TestCom();
tt.execute(cmd);
}
public void execute(String[] command) {
try {
Process process = Runtime.getRuntime().exec(command);
InputStreamReader rd = new InputStreamReader(process.getInputStream());
BufferedReader input = new BufferedReader(rd);
while(input.readLine() != null) {
System.out.println(input.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
String[] cmd = new String[]{"/bin/sh", "-c", "ls"};
TestCom tt = new TestCom();
tt.execute(cmd);
}
public void execute(String[] command) {
try {
Process process = Runtime.getRuntime().exec(command);
InputStreamReader rd = new InputStreamReader(process.getInputStream());
BufferedReader input = new BufferedReader(rd);
while(input.readLine() != null) {
System.out.println(input.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}