繁体   English   中英

使用 ProcessBuilder 运行 bash/python 脚本

[英]Running bash/python script with ProcessBuilder

我想使用 ProcessBuilder 运行 bash 脚本。 这是我的 xtend 代码:

new ProcessBuilder().inheritIO().command("/bin/bash", "-c", "./myscript.sh")

这是我的 bash 脚本:

#!/bin/bash
python WebRoot/result.py

和python代码:

#! /usr/bin/env python
import rospy
from std_msgs.msg import Empty
...

问题是我收到一个错误:

Traceback (most recent call last):
  File "WebRoot/result.py", line 2, in <module>
    import rospy
ImportError: No module named rospy

但是,当我通过终端手动运行代码时,它工作正常。

当您在命令行中运行它时,您可能会获得与它在 JVM 中运行时不同的环境。 在您的 bash 脚本中,尝试直接指向您打算使用的 python 版本。 JVM 的 env 完全有可能指向不同版本的 python。 或者环境没有完全设置好。

尝试放置完整路径,例如:

#!/bin/bash
/usr/bin/python2.7/python WebRoot/result.py

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM