Python:subprocess.Popen返回OSError:[Errno 2]没有这样的文件或目录

时间:2015-09-11 17:20:49

标签: python python-2.7 subprocess

在我的剧本中,我有以下一行:

proc = subprocess.Popen(["qstat", "-xml", "-u", "*", "-r", "-s", "r"],  stdout=subprocess.PIPE)

当我运行它时工作正常,但当它被设置为cronjob时我会回来:

Traceback (most recent call last): File 
File "/seq/software/current/bin/createOpsDashboard.py", line 171, 
in get_pod_occupied_slots
proc = subprocess.Popen(["qstat", "-xml", "-u", "*", "-r", "-s", "r"], stdout=subprocess.PIPE)
File "/software/free/Linux/redhat_5_x86_64/pkgs/python_2.7.1-sqlite3-rtrees/lib/python2.7/subprocess.py", line 672, in __init__ errread, errwrite)
File "/software/free/Linux/redhat_5_x86_64/pkgs/python_2.7.1-sqlite3-rtrees/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

造成这种情况的原因是什么? cronjob正在调用一个加载Python-2.7的shell脚本,然后调用真实的脚本。

1 个答案:

答案 0 :(得分:4)

使用" qstat"的完整路径,例如"在/ usr / local / bin中/ qstat命令&#34 ;. cronjob的PATH环境变量通常限制为默认路径(例如/ bin:/ usr / bin)。