Dear Forum members,
Can you please check below code. It doesn't prompt for telnet when I try to execute telnet command. I need to make an alternative shell where user can execute any command. please help.
import java.io.*; public class MyShell { public static void main(String[] args) throws java.io.IOException { String commandLine; String command[] = new String[1000]; BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("banglalink#"); commandLine = console.readLine(); System.out.println(commandLine); if (commandLine.equals("")) continue; command = commandLine.split(" "); System.out.println(command[0]); // System.out.println(command[1]); String s = ""; try { ProcessBuilder pb=new ProcessBuilder(command); Process pr=pb.start(); pr.waitFor(); int rc=pr.exitValue(); System.out.println(rc); if (pr.exitValue()==0) { BufferedReader outReader=new BufferedReader(new InputStreamReader(pr.getInputStream())); System.out.println("Here is the standard output of the command:\n"); while ((s = outReader.readLine()) != null) { System.out.println(s); } } else if (pr.exitValue()== -1) { System.out.println("Error while getting PID"); // return ""; } else{ pr.waitFor();} } catch (Exception e) { e.printStackTrace(); } } } }