Created
September 25, 2020 05:33
-
-
Save arifsuhan/9e216c0014f020aab67686560a96df78 to your computer and use it in GitHub Desktop.
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.util.Scanner; | |
| import java.io.*; | |
| class main{ | |
| public static Scanner input = new Scanner(System.in); | |
| public static String userInput() { | |
| String user = ""; | |
| System.out.print(">"); | |
| user = input.nextLine(); | |
| return user; | |
| } | |
| public static void runCommand(String user_cmd){ | |
| try{ | |
| Process process = Runtime.getRuntime().exec(user_cmd); | |
| printResults(process); | |
| }catch(Exception ex){ | |
| ex.printStackTrace(); | |
| } | |
| } | |
| public static void printResults(Process process) throws IOException { | |
| BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
| String line = ""; | |
| while ((line = reader.readLine()) != null) { | |
| System.out.println(line); | |
| } | |
| } | |
| public static void main(String[] args){ | |
| runCommand(userInput()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment