Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Child process cannot execute properly for telnet command

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Child process cannot execute properly for telnet command

    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();
    } 
     
    	  }
    	 }
    	}


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java Child process cannot execute properly for telnet command

    Did you write this code? What happens when it compiles?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Code doesn't execute properly
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 12:36 PM
  2. Replies: 2
    Last Post: October 29th, 2010, 03:14 AM
  3. GUI does not pop up in child process before parent is killed
    By Antipeko2 in forum Java Theory & Questions
    Replies: 0
    Last Post: February 26th, 2010, 06:32 AM
  4. How to execute a Java program independent of Netbeans.
    By ShaunB in forum Java Theory & Questions
    Replies: 4
    Last Post: January 19th, 2010, 06:23 AM
  5. opening Telnet Command Session
    By voyager in forum Java Networking
    Replies: 3
    Last Post: June 23rd, 2009, 10:34 AM

Tags for this Thread