How can I run ros commands through a C based system() call?
I have this c based program to do some benchmarking and whatnot which I use heavily. I am a ROS noob, just starting to delve into ROS code to do some analysis.
Currently, I need to be able to call ros based commands (i.e. rosbag play, roscore, etc) through the system() function. For those who do not know how it works, it basically just executes the command (i.e. system("ls"); system("./testScript.sh").
Right now I have a bash script set up to essentially run several small things including ROS commands. Executing the script works perfectly, but executing it through system always give me an error regarding ROS_cmd: Not found.
For example:
#/bin/bash
ls
echo hi
rosbag play rotating_detergent_1_6.bag
Gives me output error of : rosbag: not found - all the while executing the ls and echo This happens independent of the ROS based command.
Any one know what is wrong?
edit: So to add, the C program is called in sudo. I noticed that the problem seems to be that system() executing in sudo does not have the appropriate ROS PATH.
For example:
echo $PATH -> /opt/ros/melodic/bin : rest
sudo su; echo $PATH -> rest
How should I go about properly addressing this?