• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Unix InputStream /n problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic