I am working on on a tool to connect to a remote server using jcraft.JSch (ssh to Unix server) and return the output and display its output (something like putty, but iam not keen on Plink or any third party thing). The code works fine when channel input outputs are System.in
and System.out
and the program is just a console java application. But when I try with SWT controls, it was having problem as explained in How to Map System.out and System.in to SWT controls
so, I believe its something anout the INFO and ERR tagging (which i will deal with later), anyways i changed the approach. now iam feeding commands through a SWT Text input. its working fine for single line outputs. but not for multi line.
The code which triggers the connection to shell and sends commands is as follows.
public void widgetSelected(SelectionEvent e) {
String command=CmdText.getText();
System.out.println("runButton.widgetSelected:Command Obtained by buton is:"+command);
if ( command.equals("") )
{
MessageDialog.openInformation(dialogShell,"Information","Please Eneter a Command!");
return;
}
else if (command.contains("@"))
{
channel=CommandHandler.openshell();
LogText.append("Connected to - :"+command+"\n>");
}
else
{
LogText.append(command+"\n");
String outputstring="";
try
{
BufferedReader dataIn = new BufferedReader(new InputStreamReader(channel.getInputStream()));
DataOutputStream dataOut = new DataOutputStream(channel.getOutputStream());
dataOut.writeBytes(command+"\n");
dataOut.flush();
String line="";
outputstring=""+line;
while ( line != null) {
try
{
line = dataIn.readLine();
line = dataIn.readLine();
LogText.append("<CommandResult>:"+line+"\n");
return;
}
catch (IOException e1) { B24IDEConsole.WriteLog("RemoteCall.connect_execute", e1.getMessage()); }
outputstring=outputstring+line;
}
}
catch(Exception e1){ B24IDEConsole.WriteLog("RemoteCall.connect_execute", e1.getMessage()); }
LogText.append("<EndOfCommand>:"+outputstring+"\n");
}
}
When i remove return in the while loop the dialog and the eclipse (triggering the dialog) becomes un-responsive and i have to kill them both.
Any Help is appreciated, thank you for your time.