使用Python子进程读取journalctl输出

2024-06-01 10:16:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python从journalctl中读取系统日志的最后600秒。从命令行执行以下操作:

~ $ journalctl --since='600 seconds ago' --no-pager -p6..6
-- Logs begin at Sat 2016-05-28 09:43:08 CEST, end at Sun 2016-05-29 10:43:30 CEST. --
May 29 10:41:57 rbian dhclient[234]: DHCPREQUEST on eth0 to 10.0.1.2 port 67
May 29 10:41:57 rbian dhclient[234]: DHCPACK from 10.0.1.2
May 29 10:41:57 rbian dhclient[234]: bound to 10.0.1.11 -- renewal in 3177 seconds.

但是,当我尝试在python中使用子进程执行此操作时,会得到以下结果:

^{pr2}$

那么,这是怎么回事?我错过了什么?在


Tags: tono命令行agomayatseconds系统日志