在执行命令时,使用子进程收到“找不到逗号的错误”

时间:2018-07-18 06:45:34

标签: python-2.7 cron

import subprocess
cmd = 'command of a tool which I created'
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT, shell=True)
output, error = process.communicate()

虽然在cron中调度命令不起作用,但是可以正常工作。当我们手动执行同一命令时。

注意:这是客户端工具运行命令。

* / 1 * * * *用户名cd / path / of / the / file / &&“运行文件的命令”

```
log file:
test_tool (test_tool.TestTool) ... /bin/bash: command not found
ERROR


ERROR: test_tool (test_tool.TestTool)
----------------------------------------------------------------
Traceback (most recent call last):
File "test_tool.py", line 41, in test_nferx
data = json.loads(output.split('\n')[0])
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

0 个答案:

没有答案