Created
May 9, 2011 21:45
-
-
Save jaydonnell/963487 to your computer and use it in GitHub Desktop.
pj code
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.*; | |
public class JavaSystemCalls { | |
public static void main(String args[]) { | |
String s = null; | |
try { | |
BufferedReader stdin = new BufferedReader | |
(new InputStreamReader(System.in)); | |
String message; // Creates a varible called message for input | |
System.out.print ("Enter the message : "); | |
System.out.flush(); // empties buffer, before you input text | |
message = stdin.readLine(); | |
Process p = Runtime.getRuntime().exec(message); | |
BufferedReader stdInput = new BufferedReader(new | |
InputStreamReader(p.getInputStream())); | |
BufferedReader stdError = new BufferedReader(new | |
InputStrea | |
BufferedReader stdInput = new BufferedReader(new | |
InputStreamReader(p.getInputStream())); | |
BufferedReader stdError = new BufferedReader(new | |
InputStreamReader(p.getErrorStream())); | |
System.out.println("Command:\n"); | |
while ((s = stdInput.readLine()) != null) { | |
System.out.println(s); | |
} | |
System.out.println("Error in reading:\n"); | |
while ((s = stdError.readLine()) != null) { | |
System.out.println(s); | |
} | |
System.exit(0); | |
} | |
catch (IOException e) { | |
System.out.println("Exception in execution "); | |
e.printStackTrace(); | |
System.exit(-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment