我试图抓住uart-line并将此字符串赋予shell脚本;抓住串行输入行并将它们移动到shell脚本
#!/usr/bin/env python
import os
import serial
ser = serial.Serial('/dev/ttyAMA0', 4800)
while True :
try:
state=ser.readline()
print(state)
except:
pass
所以,“状态”应该给一个shell脚本现在, 像:myscript.sh "This is the serial input..."
但我怎么能做到这一点?
print(os.system('myscript.sh ').ser.readline())
不起作用。
'os.system()'不会返回任何你想'打印'的东西。如果子进程向标准输出输出任何东西,那就是它将要去的地方,并且你的Python脚本不会知道。如果你想捕获子进程打印的内容,你有另一个理由来看看'subprocess'模块,特别是'check_output'方法(Python 2.7+) – tripleee