[EDITED ANSWER]
The thing is, when you run the example script, it will quit immediately. Also closing any process immediately after opening it.
To keep the process running you can modify roslaunch API example and integrate it into a ROS node:
- import rospy to write a ROS Node
- Declare a node using init_node()
- Keep python from exiting until this node is stopped using rospy.spin()
So this is a simple usage example integrated into a ROS node :
import rospy
import roslaunch
rospy.init_node('roslaunch_api_test')
package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
rospy.spin()
If you don't want to create a ROS node, find a different way to keep the process running, for instance:
import roslaunch
import time
package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)
launch = roslaunch.scriptapi.ROSLaunch()
launch.start()
process = launch.launch(node)
# keep process open for 2 seconds, then quit
time.sleep(2.0)