Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
Created September 25, 2020 05:33
Show Gist options
  • Select an option

  • Save arifsuhan/9e216c0014f020aab67686560a96df78 to your computer and use it in GitHub Desktop.

Select an option

Save arifsuhan/9e216c0014f020aab67686560a96df78 to your computer and use it in GitHub Desktop.
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