所以,我有一个 bash 脚本,它在 shell 中以字符串格式从连接到 NVidea Jetson TK-1 的传感器输出数据。有什么办法可以运行初始化 bash 脚本的 python 脚本。在 bash 中获取输出数据,将其反馈到可以解析的 python 字符串变量中?我无法编辑 bash 脚本。
谢谢
最佳答案
在 python 中:
import subprocess
bash_output = subprocess.check_output('run bash script here')
Subprocess.check_output 将命令发送到 shell,然后 shell 将结果通过管道返回给 python。查看有关 subprocess.check_output
的使用示例和文档 here .
关于python - 有没有办法将 bash 脚本的输出到 "feed"到最初执行操作的 python 脚本中的变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31818259/