Go Back   Velocity Reviews > General Computer Discussion > General Help Related Topics
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

General Help Related Topics - java -issue with runtime.exec

 
Thread Tools Search this Thread
Old 12-11-2007, 08:46 PM   #1
Red face java -issue with runtime.exec


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 ", 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>


pressley
pressley is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Digital DIGEST - LIVE UPDATE Issue 41 Ablang DVD Video 0 01-05-2004 11:54 PM
Re: odd motherboard issue hootnholler A+ Certification 0 12-19-2003 06:34 AM
Digital DIGEST - LIVE UPDATE Issue 40 Ablang DVD Video 0 12-15-2003 02:45 PM
Digital DIGEST - LIVE UPDATE Issue 39 Ablang DVD Video 0 11-29-2003 02:17 AM
Digital DIGEST - LIVE UPDATE Issue 38 Ablang DVD Video 0 11-09-2003 01:31 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46