admin管理员组文章数量:1415100
I have some code which report status of a Pi using inxi
. It runs fine from a terminal, but when it runs from cron it adds some characters and misses others.
This is the code:
#!/home/pi/.venv/bin/python
import subprocess
ret = subprocess.run(['inxi -F'], shell = True, capture_output = True)
if ret.stderr.decode():
print(f'Errors = {ret.stderr.decode()}')
print(f'StdOut = {ret.stdout.decode()}')
rpt = open('/home/pi/v04_8/inxi.rpt', 'w')
rpt.write(ret.stdout.decode())
rpt.close()
This is the start of the output when run from a terminal:
System:
Host: pi-radio Kernel: 6.6.31+rpt-rpi-v7 arch: armv7l bits: 32
Console: pty pts/0 Distro: Raspbian GNU/Linux 12 (bookworm)
Machine:
Type: ARM System: Raspberry Pi 2 Model B Rev 1.1 details: BCM2835
rev: a01041 serial: 000000000fd84202
This is that same section when run from cron, note that there is an ascii 3 before the '12' which doesn't show on this page:
12System:
12Kernel 6.6.31+rpt-rpi-v7 12arch armv7l 12bits 32 12Console N/A 12Distro Raspbian GNU/Linux 12 (bookworm)
12Machine:
12Type ARM 12System Raspberry Pi 2 Model B Rev 1.1 12details BCM2835 12rev a01041 12serial <filter>
Why does this happen? Thanks Mick
本文标签: Why are there output differences when running Python code from cronStack Overflow
版权声明:本文标题:Why are there output differences when running Python code from cron? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214147a2648063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论