python - 有没有办法将 bash 脚本的输出到 "feed"到最初执行操作的 python 脚本中的变量中?

标签 python linux bash shell asus-xtion

所以,我有一个 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/

相关文章:

bash - 如何通过精确搜索而不是前缀搜索来访问 bash 历史记录?

linux - 如何在 linux/bash/unix 中查找日期时间之间经过的 UTC 24 小时?

linux - 开关不工作

bash - 查找共享部分文件名的文件

python - 使用python修改文本文件中的变量值

python - 回文无法通过所有测试用例

linux - 在 debian 中更新包

c - mmap() 拥有内存块

python - 我不明白 Django 中的测试,你能帮帮我吗?

python - 为什么Processing.py 跳过数组的倒数第二项?