conn.sendall(os.system(..sh))未为我的客户端python发送

conn.sendall(os.system(..sh))未为我的客户端python发送,python,python-2.7,Python,Python 2.7,我想在socket服务器中为我的客户发送: conn.sendall(os.system('./sensor1.sh')) sensor1.sh的代码为: #!/bin/bash i2cget -y 1 0x48 0x00 w | awk '{printf("%.1f\n",(a=(\ (("0x"substr($1,5,2)substr($1,3,1))*0.0625))\ )> 128?a-256:a)}' 这项工作很好,我可以看到我的温度传感器的变化,但我不能为我的客户发送信息。

我想在socket服务器中为我的客户发送:

conn.sendall(os.system('./sensor1.sh'))
sensor1.sh的代码为:

#!/bin/bash
i2cget -y 1 0x48 0x00 w |
awk '{printf("%.1f\n",(a=(\
(("0x"substr($1,5,2)substr($1,3,1))*0.0625))\
)> 128?a-256:a)}'
这项工作很好,我可以看到我的温度传感器的变化,但我不能为我的客户发送信息。错误是: 必须是字符串或缓冲区,而不是int


如何解决此问题?

os.system
返回子流程的退出状态。如果要发送传感器1.sh的输出:

import subprocess

...
conn = ...
...

out = subprocess.check_output(['./sensor1.sh'])
conn.sendall(out)

@DuarteValente,请显示错误消息/回溯。顺便说一句,我没有使用任何Python-3.x功能。
out=subprocess.check_output(['./sensor1.sh'])
为什么你认为
shell=True
是必要的?这是错误:out=subprocess.check_output(['sensor1.sh'],shell=True)文件/ur/lib/python2.7/subprocess.py”,第544行,在check_output raise CalledProcessError(retcode,cmd,output=output)subprocess.CalledProcessError:Command'[sensor1.sh']'返回非零退出状态127i没有错误,但我没有收到任何东西