0

First of all, this may seem like a duplicate question but I have searched stack overflow/various other forum sites and still haven't managed to find a solution.

A few example forum posts I have reviewed to prove I've done my research before asking a question:

There's hundreds more but I won't include them all.

I essentially need a shell script to open a command prompt on windows, login to a remote linux system and run a command.

I am aware this can be done with the following:

start cmd /k ssh user@host ls

But the problem with the above is that the ssh connection is closed upon completion of the task. I am also aware I can keep the ssh connection open by adding:

bash -l

in some cases.

For my use case, I need to run a launch file for ROS (robot operating system) and for this I need to see the output from the command.

And when attempting to run roslaunch launchFile.launch (in place of ls above):

start cmd /k ssh user@host "roslaunch launchFile.launch"

the command prompt returns

bash: roslaunch: command not found

I've obviously sanitised the specific name of my launch file but

roslaunch launchFile.launch

runs perfectly if I login to the linux PC first:

ssh user@host

then run the command.

I have achieved this exact use case on MacOS but I now need reimplement the same solution on windows:

osascript -e 'tell app "Terminal"
     do script "ssh quantum@172.23.199.1 \n
     roslaunch launchFile.launch"
end tell'

Thanks in advance for any help or advice.

Patrick Lafferty
  • 337
  • 1
  • 7
  • 20

1 Answers1

1

Try this :

start cmd /k ssh user@host "/full/path/to/roslaunch launchFile.launch; exec /bin/bash"
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • Thanks @Philippe this really helped me find a solution. I can't believe that when the error said 'command not found' I didn't think of this. For other ROS users reading this, although calling roslaunch from its installation location (usually /opt/ros//bin/roslaunch) I'm sure helps, the main issue is that ROS was not being setup until ssh had fully logged in. When ssh user@host is used the bashrc is probably loaded at the very last stage. In short, the solution was to source the setup.bash file from the devel folder inside my catkin workspace. – Patrick Lafferty May 06 '22 at 21:05
  • I unfortunately just realised that the solution above does not resolve my problem. Sourcing the setup.bash file may give ssh access to the ROS environment but it doesn't them keep the connection open for interaction. Roslaunch or roscore is not a single command that executes and produce a single static result (like ls). Roslaunch/roscore is desgined to be left running in an active command prompt. – Patrick Lafferty May 09 '22 at 09:23