Skip to content

Instantly share code, notes, and snippets.

@mritunjay-k
Last active February 7, 2019 13:18
Show Gist options
  • Save mritunjay-k/dc03809e48b443f079a56f66b98a75fc to your computer and use it in GitHub Desktop.
Save mritunjay-k/dc03809e48b443f079a56f66b98a75fc to your computer and use it in GitHub Desktop.
This is how you make your own terminal like a BOSS !!
//Your temporary Terminal.
import java.io.*;
import java.util.Scanner;
public class Mycontrol{
public static void main(String[] args){
try{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a command");
String cmd= sc.next();
Runtime run= Runtime.getRuntime();
Process pr= run.exec(cmd);
pr.waitFor();
BufferedReader buf= new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line= " ";
while((line=buf.readLine())!=null){
System.out.println(line);
}
}
catch(Exception e){
System.out.println("Command not found");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment