----- Original Message ----
From: n schembr <[EMAIL PROTECTED]>
To: [email protected]
Sent: Friday, September 21, 2007 5:31:24 PM
Subject: [JSch-users] Can a nonblocking readline be build into the channel
class?
I'm trying to build a class that I can use like the expect command in tcl.
I'm having trouble building a nonblocking readline().
I'm working with the example shell.java. I have a good connection and I
receive no errors.
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(in.available()>0){
int i=in.read(tmp, 0, 1024);
if(i<0)break;
System.out.print(new String(tmp, 0, i));
}
if(channel.isClosed()){
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try{Thread.sleep(1000);}catch(Exception ee){}
}
If I use BufferedReader, it blocks on the last line. I have no good way to test
if the lastline has a \r.
If I use InputStream, I'm building readline from the ground up. I need to keep
track of every char I read.
Java Streams and channels are a weak spot for me.
Can a nonblocking readline be build into the channel class?
What about a look ahead buffer?
Nicholas A. Schembri
State College PA USA
-----------------------------------------------------
Ok, I'm replying to my self. :)
It looks like BufferedReader is an issue. I can see the need to expand the
ChannelShell class to include a readline method that is non-blocking.
For my application I can see a single thread connnection controlling a remote
shell.
channel = (ChannelShell) session.openChannel("shell");
channel.setPtyType("vt100");
in = channel.getInputStream();
out = new OutputStreamWriter( this.channel.getOutputStream());
channel.connect(3000);
out.write("/bin/ls\r");
out.flush();
// my idea code
String s="";
List results = new ArrayList();
while(in.available()>0{
s = in.readline();
If (s !=null){
results.add(s);
}
}
// now work with the list.
The issue is the last line is the shell prompt. The readline() should return
null or EOL.
If readline() is blocking, in.readLineAvailable() should return the number of
lines that can be read.
It might be better to have readline(s) return 0 if the line is complete or -1
for error. This would allow for the shell prompt. But this would void a call
to readline when the channel has more data. A in.unread(s) is required.
I'm trying to think of a good way to allow a large amount of data to be
interacted with.
If this can not be added to ChannelShell, I will try to create
ChannelShellExpect.
String expect(String REGEX)
void send(String Line);
int readline(String ReturnString)
boolean unread(String pushback)
Is there a better way?
Nicholas A. Schembri
State college PA USA
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users