Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ptp-user] Remote execution of bash commands with IRemoteProcessBuilder

Rocky,

The IRemoteProcessBuilder is designed to run a simple command with some arguments remotely, it is not really meant to be used to run an arbitrary shell command. I think this is the problem you’re having. The escaping is necessary so that arguments containing special characters are handled by the remote system correctly, but it will interfere with shell special characters.

The IRemoteConnection#getCommandShell() method is probably what you’re after, but unfortunately it’s only available in Luna, and is not currently implemented.

The only other option is to create a script dynamically and execute it. E.g. something like:

IFileStore tmp = connection.getFileManager().getResource(“/tmp/xxx”);
PrintStream p = new PrintStream(tmp.getOutputStream(EFS.NONE, monitor.newChild(1)));
p.println("echo \"export ESMFMKFILE=/home/sgeadmin/esmf.mk\" >> .profile”);
p.close();
IFileInfo info = tmp.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, true);
tmp.putInfo(info, EFS.SET_ATTRIBUTES, monitor.newChild(1));
IRemoteProcessBuilder pb = connection.getProcessBuilder(“/tmp/xxx”);
pb.start();


Regards,
Greg

On Jan 16, 2014, at 3:19 PM, Rocky Dunlap <rocky@xxxxxxxxxxxxx> wrote:

> 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?  What is the intention of the escaping
> mechanism?
> 
> I (incorrectly) posted this originally to the CDT forum, but I am
> redirecting the question to the PTP mailing list.
> 
> http://www.eclipse.org/forums/index.php/t/637324/
> 
> Thanks!
> Rocky
> _______________________________________________
> ptp-user mailing list
> ptp-user@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/ptp-user



Back to the top