最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why are there output differences when running Python code from cron? - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论