Prevent python scripts and cpp files to run directly, allow run only using roslaunch
I am designing a ROS (ROS Indigo on Ubuntu 14.04 LTS) package containing several python scripts and CPP files. I don't want any user to directly invoke python scripts or CPP code. For example, if any user invokes such files directly, it should exit by displaying an error message such as following:
$rosrun my_package my_script.py
[ERROR] Do not invoke this file directly. Instead, use 'roslaunch my_package my_script.launch'
$rosrun my_package my_cpp
[ERROR] Do not invoke this file directly. Instead, use 'roslaunch my_package my_cpp.launch'
Any suggestions to incorporate such behavior? Thank you very much.
To avoid a possible xy-problem, could you explain why you'd want to do this?
@gvdhoorn: I am passing many parameters to script and cpp files from launch file. If these scipt and cpp files are executed with rosrun/directly, it terminates by thowring long long exceptions. Hence i would like to show some info to prevent it.
If 'parameters' are actual ROS parameters, would checking the return value of
NodeHandle::hasParam(..)
printing an appropriate error message and thenreturn
orexit(..)
-ing not be possible?Yeah. that's what I am doing till now. and just before
exit
, I put aprint
command in each file.Then I would suggest you make the whole thing a bit more generic, and don't complain about starting things 'directly', but just error out on a missing parameter.
Launch files can be changed, there is no guarantee that all your parameters will always be there.