This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Unix InputStream /n problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Unix InputStream /n problem" Watch "Unix InputStream /n problem" New topic
Author

Unix InputStream /n problem

Enrico Presiedere
Greenhorn

Joined: Nov 25, 2004
Posts: 1
Dear Friends
I'm disperate !!!
I need to connect to a unix machine whith a java class , and get the output on the web.
My problem is that I'm non able to get the new line command ... and when I create the return string I'm not able to put <br> where is the new line!!!
this is my code :

package thor.app;

import java.net.*;
import java.io.*;
import thor.net.*;

class SimpleTelnetTerminalHandler extends DefaultTelnetTerminalHandler
implements TelnetConstants {
public void LineFeed() {
System.out.print('\n');
System.out.flush();
}
public void CarriageReturn() {
System.out.print('\r');
System.out.flush();
}
public void BackSpace() {
System.out.print((char)BS);
System.out.flush();
}
public void HorizontalTab() {
System.out.print((char)HT);
System.out.flush();
}
}

/** telnet is the simplest telnet you can write.
* It is intended to show how to use the library
* for connecting to another host. It will expose
* your password though.
*
* <pre>
* use:
* java thor.app.telnet myhost [myport]
* </pre>
*
*
* -- Daniel Kristjansson May 27, 2000
* <i>The <a href=http://www.gnu.org/copyleft/lgpl.html>LGPL</a>
* applies to this software.<br>
* Unless otherwise stated the software is
* Copyright 1996,2000 Daniel Kristjansson</i>
*/

public class netbusTelnet {
static volatile boolean closed=false;
public static String valore="";
public static void startSh(String host,int port,String user , String pwd,String cmd) throws InterruptedException{
try {
//String host = (args.length>0)?args[0]:"graphics.nyu.edu";
//int port = (args.length>1)?Integer.parseInt(args[1]):23;
URL url=new URL("telnet", host, port, "",
new thor.net.URLStreamHandler());
URLConnection urlConnection=url.openConnection();
urlConnection.connect();
if (urlConnection instanceof TelnetURLConnection) {
((TelnetURLConnection)urlConnection).
setTelnetTerminalHandler(new SimpleTelnetTerminalHandler());
}
OutputStream out=urlConnection.getOutputStream();
PrintStream pout = new PrintStream(out);
final InputStream in=urlConnection.getInputStream();
boolean login = false;
(new Thread(new Runnable() {
public void run() {
try {
int ch;
do {
ch=in.read();
if (ch<0) return;
if(ch == 10){
valore += "<BR>";
}
System.out.print((char)ch);
valore +=(char)ch;
System.out.flush();
} while(true);
} catch (Exception e) {
if (!closed) e.printStackTrace();
}
}
})).start();

Thread.sleep(5000);
pout.println(user);
Thread.sleep(5000);
pout.println(pwd);
Thread.sleep(15000);
//inserire comando
pout.println(cmd);
Thread.sleep(5000);
closed=true;
((TelnetURLConnection)urlConnection).disconnect();

} catch (IOException e) {e.printStackTrace();}
}
}

Please Help !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unix InputStream /n problem
 
Similar Threads
Global Variables in Java
Passing Ping Command Through Telnet
SSLHandshakeException
Sending mail
Gloal Variables in Java