Skip to content

Instantly share code, notes, and snippets.

@anistark
Created December 6, 2016 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anistark/27e3181735e96a3315707103bd8a5407 to your computer and use it in GitHub Desktop.
Save anistark/27e3181735e96a3315707103bd8a5407 to your computer and use it in GitHub Desktop.
Run Shell CMD via code
import java.io.*;
class Main {
public static void main(String[] args) {
String command = "ls";
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment