Report contains control characters when run in cron

Running on Raspberry Pi with bookworm.
I have some python code, “inxi_test.py”

#!/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_7/inxi.rpt',  'w')
rpt.write(ret.stdout.decode())
rpt.close()

which creates a report “inxi.rpt”

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
CPU:
  Info: quad core model: ARMv7 v7l variant: cortex-a7 bits: 32 type: MCP
  Speed (MHz): avg: 900 min/max: 600/900 cores: 1: 900 2: 900 3: 900 4: 900
Graphics:
  Device-1: bcm2835-hdmi driver: vc4_hdmi v: N/A
  Device-2: bcm2835-vc4 driver: vc4_drm v: N/A
  Display: server: No display server data found. Headless machine? tty: 138x30
  API: OpenGL Message: GL data unavailable in console. Try -G --display
Audio:
  Device-1: bcm2835-hdmi driver: vc4_hdmi
  Device-2: iqaudio-dac driver: snd_rpi_iqaudio_dac
  API: ALSA v: k6.6.31+rpt-rpi-v7 status: kernel-api
Network:
  Device-1: bcm2835-sdhci driver: N/A
  IF: eth0 state: down mac: b8:27:eb:d8:42:02
  Device-2: Microchip (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter type: USB
    driver: smsc95xx
  IF: eth0 state: down mac: b8:27:eb:d8:42:02
  Device-3: Edimax EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] type: USB
    driver: rtl8192cu
  IF: wlan0 state: up mac: 80:1f:02:af:58:23
Drives:
  Local Storage: total: 14.95 GiB used: 4.38 GiB (29.3%)
  ID-1: /dev/mmcblk0 type: Removable model: NCard size: 14.95 GiB
Partition:
  ID-1: / size: 14.18 GiB used: 4.28 GiB (30.2%) fs: ext4 dev: /dev/mmcblk0p2
Swap:
  ID-1: swap-1 type: file size: 200 MiB used: 0 KiB (0.0%) file: /var/swap
Sensors:
  System Temperatures: cpu: 58.4 C mobo: N/A
  Fan Speeds (RPM): N/A
Info:
  Processes: 147 Uptime: 3d 2h 3m Memory: 996.9 MiB used: 263.1 MiB (26.4%) gpu: 76 MiB
  Init: systemd target: multi-user (3) Shell: sh inxi: 3.3.26

and some more code almost the same “inxi_test_cron.py”

#!/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_7/inxi_cron.rpt',  'w')
rpt.write(ret.stdout.decode())
rpt.close()

which is run as cron job and creates “inxi_cron.rpt”. Code is the
same, name changes to clarify which is which.

Running inxi_test.py from a terminal creates inxi.rpt which is fine,
just as expected

Running inxi_test_cron.py as a scheduled cron job creates inxi_cron.rpt

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>
12CPU:
  12Info quad core 12model ARMv7 v7l 12variant cortex-a7 12bits 32 12type MCP
  12Speed (MHz) 12avg 700 12min/max 600/900 12cores 121 700 122 700 123 700 124 700
12Graphics:
  12Device-1 bcm2835-hdmi 12driver vc4_hdmi 12v N/A
  12Device-2 bcm2835-vc4 12driver vc4_drm 12v N/A
  12Display 12server No display server data found. Headless machine? 12tty 80x40
  12API OpenGL 12Message GL data unavailable in console. Try -G --display
12Audio:
  12Device-1 bcm2835-hdmi 12driver vc4_hdmi
  12Device-2 iqaudio-dac 12driver snd_rpi_iqaudio_dac
  12API ALSA 12v k6.6.31+rpt-rpi-v7 12status kernel-api
12Network:
  12Device-1 bcm2835-sdhci 12driver N/A
  12IF eth0 12state down 12mac <filter>
  12Device-2 Microchip (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter 12type USB 12driver smsc95xx
  12IF eth0 12state down 12mac <filter>
  12Device-3 Edimax EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] 12type USB
    12driver rtl8192cu
  12IF wlan0 12state up 12mac <filter>
12Drives:
  12Local Storage 12total 14.95 GiB 12used 4.38 GiB (29.3%)
  12ID-1 /dev/mmcblk0 12type Removable 12model NCard 12size 14.95 GiB
12Partition:
  12ID-1 / 12size 14.18 GiB 12used 4.29 GiB (30.2%) 12fs ext4 12dev /dev/mmcblk0p2
12Swap:
  12ID-1 swap-1 12type file 12size 200 MiB 12used 0 KiB (0.0%) 12file /var/swap
12Sensors:
  12System Temperatures 12cpu 55.1 C 12mobo N/A
  12Fan Speeds (RPM) N/A
12Info:
  12Processes 141 12Uptime 5d 2h 2m 12Memory 996.9 MiB 12used 250.8 MiB (25.2%) 12gpu 76 MiB 12Init systemd
  12target multi-user (3) 12Client Unknown python3.11 client 12inxi 3.3.26

which has the odd characters. There is a character before the “12” which shows on my system and in the text I pasted in, but not on the preview. The cron job is

53 22 * * * /home/pi/.venv/bin/python3 /home/pi/v04_7/inxi_test_cron.py
>> /home/pi/v04_7/logs/cron_inxi.log 2>&1 # cron_inxi_test

Why are these control characters created when run as a cron job? How can
I fix it?

Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật