Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > java -issue with runtime.exec

Reply
Thread Tools

java -issue with runtime.exec

 
 
pressley pressley is offline
Junior Member
Join Date: Dec 2007
Posts: 1
 
      12-11-2007
Hello all,

I have a unix box and am trying to do an ssh to itself using java. I am ausing the following code for that:

Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
class StreamGobbler extends Thread {
	InputStream is;
	String type;

	StreamGobbler(InputStream is, String type) {
		this.is = is;
		this.type = type;
	}

	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null)
				System.out.println(type + ">" + line);
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}
public class UnixExecTest {
	public static void main(String args[]) {

		try {
			String input = "test";

			while (!(input.equals("exit"))) {
				InputStreamReader isr = new InputStreamReader(System.in);
				BufferedReader stdin = new BufferedReader(isr);
				System.out.print("Enter command: ");
				input = stdin.readLine();
				System.out.println("input = " + input);

				String[] cmd = {"sh", "-c", input.trim()};

				Runtime rt = Runtime.getRuntime();
				System.out.println("Execing " + cmd);
				Process proc = rt.exec(cmd);

				StreamGobbler errorGobbler = new StreamGobbler(proc
						.getErrorStream(), "ERROR");

				StreamGobbler outputGobbler = new StreamGobbler(proc
						.getInputStream(), "OUTPUT");

				errorGobbler.start();
				outputGobbler.start();

				int exitVal = proc.waitFor();
				System.out.println("ExitValue: " + exitVal);
			}
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
}

Using the code above, I am able to execute the unix commands. All the basic commands like ps, ls, id etc gives perfect output. But when i try to do an "ssh http://www.velocityreviews.com/forums/(E-Mail Removed)", I see an error message "Pseudo-terminal will not be allocated because stdin is not a terminal." Then after a couple of seconds, it shows me the welcome message like its supposed to be and asks for my password. as soon as I wnter my password, it gives me an error message like :

ttytype: couldn't open /dev/tty for reading
stty: : Not a typewriter
Not a terminal
Not a terminal
stty: : Not a typewriter
stty: : Not a typewriter
resize: Can't open terminal /dev/tty

and then looks like the program is hanging and doesnt do anything. I am expecting a unix promt to come up for entering commands. Any ideas on where i am going wrong ? I'd really appreciate any help.

Thank you !!

Let me paste the contents of the output screen once again:

Code:
ERROR>Pseudo-terminal will not be allocated because stdin is not a terminal.
ERROR>
ERROR>************************************************************************
ERROR>**                                                                    **
ERROR>**                     THIS SYSTEM IS RESTRICTED!                     **
ERROR>**                                                                    **
ERROR>**   You are authorized to use this system for approved business      **
ERROR>**   purposes only.  Use for any other purpose is prohibited.  All    **
ERROR>**   transactional records, reports, e-mail, software, and other      **
ERROR>**   data generated by or residing upon this system are the property  **
ERROR>**   of the Company and may be used by the Company for any purpose.   **
ERROR>**   Authorized and unauthorized activities may be monitored.         **
ERROR>**                                                                    **
ERROR>************************************************************************
ERROR>
ERROR>************************************************************************
ERROR>*                                                                      *
ERROR>*  CAUTION: You have reached a restricted access system.               *
ERROR>*           Unauthorized use of this system is prohibited and will     *
ERROR>*           be prosecuted to the fullest extent of the law.            *
ERROR>*                                                                      *
ERROR>************************************************************************
ERROR>

Enter user's Password:
ERROR>ttytype: couldn't open /dev/tty for reading
ERROR>stty: : Not a typewriter
ERROR>Not a terminal
ERROR>Not a terminal
ERROR>stty: : Not a typewriter
ERROR>stty: : Not a typewriter
ERROR>resize: Can't open terminal /dev/tty
OUTPUT>
OUTPUT>
OUTPUT>
OUTPUT>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hot Requirements: 1.Sr Java Developer,2.Java Developer (Java with EJB) Isaac Java 0 01-20-2011 08:41 PM
hey i am just started java,, can anyone tell me the use ,application, why java , importance of java.. manish sahu Java 3 02-14-2008 12:00 AM
[JAVA] [EVALUATION] - The Java Failure (Sorry: The Java(tm) Failure) Ilias Lazaridis Java 0 02-01-2005 10:32 AM
JAVA VIRTUAL MUCHINE OR SUN JAVA Fernando Kohan Firefox 1 11-14-2004 02:04 AM
Job to convert Java App 1.3.1 to Java Newest of Java Michael Kintner Java 0 11-30-2003 04:42 AM



Advertisments