After executing remote command the output objects were not returned properly
Bugzilla Link | 462836 |
Status | NEW |
Importance | P3 major |
Reported | Mar 23, 2015 07:22 EDT |
Modified | Mar 23, 2015 07:24 EDT |
Reporter | Chandrayya |
Description
The line cmdSS.sendCommandToShell(command.toString(), shell, null); in the below code will not return output objects properly when there is not thread delay(Thread.sleep(1000);) is added. When thread delay is added then the line shell.getRoots(); will return output objects properly.
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.shells.ui.RemoteCommandHelpers;
import org.eclipse.rse.subsystems.processes.core.subsystem.impl.RemoteProcessImpl;
import org.eclipse.rse.subsystems.shells.core.model.RemoteCommandShell;
import org.eclipse.rse.subsystems.shells.core.model.RemoteOutput;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
public class MyHandler extends AbstractHandler {
/**
* Default handler\
*/\
@Override\
public Object execute(ExecutionEvent event) throws ExecutionException {\
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);\
IStructuredSelection sel = (IStructuredSelection) window
.getSelectionService().getSelection();\
RemoteProcessImpl ele = (RemoteProcessImpl) sel.getFirstElement();\
IHost conn = ele.getSystemConnection();\
IRemoteCmdSubSystem cmdSS = RemoteCommandHelpers.getCmdSubSystem(conn);\
try {\
cmdSS.checkIsConnected(null);\
} catch (SystemMessageException e2) {\
e2.printStackTrace();\
}\
StringBuffer command = new StringBuffer();\
command.append("ls -l");\
Object[] obs = null;\
RemoteOutput fe = null;\
try {\
try {\
cmdSS.initializeSubSystem(null);\
} catch (SystemMessageException e1) {\
e1.printStackTrace();\
}\
RemoteCommandShell shell = null;\
try {\
shell = (RemoteCommandShell) cmdSS.getDefaultShell();\
} catch (Exception e) {\
e.printStackTrace();\
}\
shell.removeOutput();\
cmdSS.sendCommandToShell(command.toString(), shell, null);\
Thread.sleep(1000); //If removed this line output objects were not returned properly\
obs = new Object[shell.getRoots().length];\
obs = shell.getRoots();\
for (int i = 0; i < obs.length; i++) {\
fe = (RemoteOutput) obs[i];\
String op1 = fe.getText();\
System.out.println(op1); \
}\
\
command.setLength(0);\
command.append("ps aex");\
shell.removeOutput();\
cmdSS.sendCommandToShell(command.toString(), shell, null);\
Thread.sleep(1000);//If removed this line output objects were not returned properly\
obs = shell.getRoots();\
for (int i = 0; i < obs.length; i++) {\
fe = (RemoteOutput) obs[i];\
String op1 = fe.getText();\
}\
} catch (Exception e) {\
e.printStackTrace();\
}\
return null;\
}\
}