[英]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.