Created
December 6, 2016 07:24
-
-
Save anistark/27e3181735e96a3315707103bd8a5407 to your computer and use it in GitHub Desktop.
Run Shell CMD via code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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