RE: why My main thread exit when IOStreamConnectorThread exits?
"ACE Pedro Duarte" <[email protected]>
| Newsgroups | gmane.comp.java.sshtools.user |
|---|---|
| Message-ID | <[email protected]> |
Are you sure that your program reaches Here
" //wait untill the command is executed and read the
result from the file
cmdd ="exit\n";
out.write(cmdd.getBytes());"
Hi have a problem very similar, I´ve to load the environmental variables defined by the user shell so, I do a startShell() then execute the command env like you execute the command above., I can get the command result but the next command ( exit ) do not run.
What are you doing in "//wait untill the command is executed and read the" ?
Thanksx
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of mahshid shakiba
Sent: quarta-feira, 26 de Maio de 2004 21:40
To: [email protected]
Subject: [Sshtools-users] why My main thread exit when IOStreamConnectorThread exits?
Hi,
I have started using SSHTools in my application one month ago. My
application should connect and run commands on the remote server
regularly. In my main application I have loop and in this loop I will run
the commands on the remote server. My problem is that after the first use
of openSessionChannel() , startshell() and finally exiting the usershell,
my main thread also seems to exit.
Here is an example of my code:
public class myclass()
{
static SshClient ssh=null;
static SessionChannelClient shell_session=null;
//it is a swing application
public myclass()
{
//initialize my frame and panel ...
}
public static void main(String[] args)
{
//initialize the ssh with password authentication
myclass my=new myclass();
while(true)
{
System.out.println("reached here"); //only printed once!!
I do not know why??
shell_session = ssh.openSessionChannel();
if (!shell_session.requestPseudoTerminal("vt100", 80, 24, 0,
0, ""))
{ System.out.println("Failed to allocate a pseudo terminal");
shell_session.close();
throw(new Exception());
}
if (shell_session.startShell())
{
IOStreamConnector output,error;
output = new IOStreamConnector();
error = new IOStreamConnector();
myStdOutPrintStream = new PrintStream(
new
BufferedOutputStream(
new
FileOutputStream(new File("c:\\myoutput.txt")) ));
output.connect(shell_session.getInputStream(),
myStdOutPrintStream);
error.connect(shell_session.getStderrInputStream(),
System.out);
OutputStream out = shell_session.getOutputStream();
String cmdd="runblast" + "\n";
out.write(cmdd.getBytes());
//wait untill the command is executed and read the
result from the file
cmdd ="exit\n";
out.write(cmdd.getBytes());
shell_session.getState().waitForState(ChannelState.CHANNEL_CLOSED);
output=error=null;
shell_session.close();
shell_session=null;
} //if
}//while
} //main
} //myclass
after the "INFO: IOStreamConnectorThread is exiting" in log , the
"reached here" message is not displayed anymore. It seems like as if my
main thread exited with IoStreamConnector!!
I appreciate if you can help me.
Thanks for your time and have a great day.
Mahshid
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Sshtools-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sshtools-users
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id66&op=click