0

I want to execute a script with a ProcessBuilder(). My code is:

new ProcessBuilder().inheritIO().command("/bin/bash", "-c", "./deploy.sh").start();

In the bash script I have:

#!/bin/bash
rosrun my_package ardrone_test_1.py

It works if I run the bash script manually in the terminal, but if I do with the ProcessBuilder I got an error:

rosrun: command not found

The same if I run python scripts which uses ROS. There are errors that some package are not found, whereas it works fine if run via terminal.

  • Have you called the setup script before? Are you sure the environment variables are set how they should? – kutschkem Jun 14 '19 at 15:03
  • Probably your environment is not setup properly, you should provide the path to `rosrun`. You can have a look at [Java ProcessBuilder not able to run Python script in Java](https://stackoverflow.com/questions/26171862/java-processbuilder-not-able-to-run-python-script-in-java) – Butiri Dan Jun 14 '19 at 15:07
  • @Kutschkem I run the script from the terminal and it works so I also assume all env variables are also set correctly, but I have already checked them, as well, and it seems fine. – Grzegorz Brzęczyszczykiewicz Jun 14 '19 at 15:14
  • @ButiriDan how I can provide a path to rosrun? I have seen the post you send me and I provide an absolute path when I run the python script, but it doesn't help, unfortunately. – Grzegorz Brzęczyszczykiewicz Jun 14 '19 at 15:18
  • `rosrun` might be an alias, which wouldn't be resolved when calling `bash -c rosrun`. Use `type rosrun` in the terminal where it works to find out. If it's an alias then stop relying on it and use the aliased command instead of the alias. If it's not, `type` will tell you where the executable is and an easy fix would be to use that in the script instead of just rosrun – Aaron Jun 14 '19 at 15:38
  • @GrzegorzBrzęczyszczykiewicz have you try to source the setup file? To add `source /opt/ros/hydro/setup.bash` at the beginning of your bash file and maybe you will also have to export the path to rosrun or BASH_ENV (you can do this from the bash file or from the process environment `ProcessBuilder.environment` [Setting the environment for ProcessBuilder](https://stackoverflow.com/questions/10035383/setting-the-environment-for-processbuilder)) – Butiri Dan Jun 14 '19 at 20:18

0 Answers0