是的,在执行所需的ROS命令之前,应该足以获取安装脚本,例如:
#!/usr/bin/env python from subprocess import Popen, PIPE shell_setup_script = "/some/path/to/workspace/devel/setup.sh" command = "echo $ROS_PACKAGE_PATH" cmd = ". %s; %s" % (shell_setup_script, command) output = Popen(cmd, stdout=PIPE, shell=True).communicate()[0] print(output)
正如你看到的, shell=True 使用,将执行 cmd 在子壳中。然后, cmd 包含 . <shell_setup_script>; <command> 在执行命令之前获取安装脚本。请注意 .sh 文件来源而不是 .bash 因为Popen可能会使用通用的POSIX shell。
shell=True
cmd
. <shell_setup_script>; <command>
.sh
.bash