我正在处理将从journalctl过滤特定日志的脚本。对于上次运行的位置,我使用的是光标,它指向journalctl中的特定行
获取我正在使用的日记:
journal = subprocess.check_output(['journalctl', '-c "s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"'])
但我收到错误:
Failed to seek to cursor: Invalid argument
Traceback (most recent call last):
File "GlobalLogger.py", line 28, in <module>
journal = subprocess.check_output(['journalctl', '-c "s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"'])
File "/usr/lib64/python2.7/subprocess.py", line 575, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['journalctl', '-c "s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"']' returned non-zero exit status 1
但是当我把这个命令直接放到命令窗口时:
journalctl -c "s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"
完美无缺。
也是例如:
subprocess.check_output(['journalctl', '-q'])
工作正常
是否有可能为subprocess.check_output处理太长的参数? 或者哪里有问题?
答案 0 :(得分:1)
['journalctl', '-c "s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"']
应该是
['journalctl', '-c', '"s=b5b4b91f4c7b4818b65091488f050d2c;i=cab;b=2aa19337e07b45a3b1512f0cbfb37022;m=12e4d43961;t=56e92fc5786c7;x=a68e963efa2c81f4"']
每个参数都应该被拆分。