Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Remote execution of bash commands with IRemoteProcessBuilder(How to programmatically execute bash commands on a remote system using RemoteTools)
Remote execution of bash commands with IRemoteProcessBuilder [message #1231468] Tue, 14 January 2014 13:59
Rocky Dunlap is currently offline Rocky Dunlap
Messages: 12
Registered: July 2009
Junior Member
I am attempting to execute the following bash command on a remote system programmatically using RemoteTools:

echo "export ESMFMKFILE=/home/sgeadmin/esmf.mk" >> .profile


Here is the relevant code snippit.

IRemoteServices remoteServices = RemoteServices.getRemoteServices("org.eclipse.ptp.remote.RemoteTools", new SubProgressMonitor(monitor,1));

IRemoteConnection remoteConn = ....;  //acquire remote connection

String command = "echo \"export ESMFMKFILE=/home/sgeadmin/esmf.mk\" >> .profile";
IRemoteProcessBuilder rpb = remoteServices.getProcessBuilder(remoteConn, command);
IRemoteProcess rp = rpb.start();
    
while (!rp.isCompleted()) {
   rp.waitFor();
}

// print stdout
System.out.println("\nProcess stdout:");
BufferedReader in = new BufferedReader(new InputStreamReader(rp.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
in.close();

//print stderr
System.out.println("\nProcess stderr:");
in = new BufferedReader(new InputStreamReader(rp.getErrorStream()));
while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);
in.close();


The stderr output of sending the above command is:

Process stderr:
stdin: is not a tty
/bin/bash: echo "export ESMFMKFILE=/home/sgeadmin/esmf.mk" >> .profile: No such file or directory


Actually, even the simple command "echo hello" returns a similar error. Upon digging into the RemoteConnection object, I find the RemoteScript object and the actual command that is sent. It has undergone some serious character escaping:

echo\ \"export\ ESMFMKFILE\=/home/sgeadmin/esmf.mk\"\ \>\>\ .profile


This escaping is built into RemoteToolsProcessBuilder.

My question is how would I go about executing the above command using the RemoteToolsProcessBuilder?

Previous Topic:CDT not recognizing IN and OUT keywords
Next Topic:How to set GDB breakpoint actions?
Goto Forum:
  


Current Time: Tue Sep 02 03:00:41 EDT 2014

Powered by FUDForum. Page generated in 0.01620 seconds