Created
November 25, 2016 20:59
-
-
Save LearnItCodeIt/7a21cd121048cbb2025c1c9d2a407701 to your computer and use it in GitHub Desktop.
the output of this method is the same output of the command variable if you typed in cmd because it create a cmd process and input the command variable then take the output and return it
This file contains hidden or 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.BufferedReader; | |
import java.io.InputStreamReader; | |
class CommandPrompt { | |
public static void runSystemCommand(String command) { | |
try { | |
Process p = Runtime.getRuntime().exec(command); | |
BufferedReader inputStream = new BufferedReader( | |
new InputStreamReader(p.getInputStream())); | |
String s = ""; | |
// reading output stream of the command | |
while ((s = inputStream.readLine()) != null) { | |
System.out.println(s); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment