SLURM squeue 格式参数从 subprocess.Popen 开始失败
SLURM squeue format argument fails from subprocess.Popen
我正在尝试从 python 脚本调用 SLURM squeue。命令,
/usr/bin/squeue --Format=username,jobid,name,timeleft
在命令行中工作正常,但在 subprocess.Popen
中失败:
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/n/home00/DilithiumMatrix/.conda/envs/py35/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/n/home00/DilithiumMatrix/.conda/envs/py35/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/squeue --Format=username,jobid,name,timeleft'
MWE:
import subprocess
command = "/usr/bin/squeue --Format=username,jobid,name,timeleft"
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
text = p.stdout.read()
print(text)
/usr/bin/squeue
从命令行或 Popen
.
都可以正常工作
它是否会失败,因为它需要一些关于正在执行 squeue
命令的 user/group 的信息,并且当 运行 通过 python 时,这些信息(不知何故)丢失了?还有什么可能导致这种情况?
subprocess.Popen
的第一个参数是字符串或字符串列表。如果它是单个字符串,它将被解释为文件名。这就是您收到错误的原因。
要传递字符串列表,它应该与 shell 将您的参数传递给进程的方式相匹配。标准的 shell 会用空格分割你的命令行,所以不要这样:
command = "/usr/bin/squeue --Format=username,jobid,name,timeleft"
你需要这个:
command = ["/usr/bin/squeue", "--Format=username,jobid,name,timeleft"]
正如您在评论中提到的那样,在“=”处拆分第二个参数只会混淆 squeue,然后它会看到两个参数。
我正在尝试从 python 脚本调用 SLURM squeue。命令,
/usr/bin/squeue --Format=username,jobid,name,timeleft
在命令行中工作正常,但在 subprocess.Popen
中失败:
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/n/home00/DilithiumMatrix/.conda/envs/py35/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/n/home00/DilithiumMatrix/.conda/envs/py35/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/squeue --Format=username,jobid,name,timeleft'
MWE:
import subprocess
command = "/usr/bin/squeue --Format=username,jobid,name,timeleft"
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
text = p.stdout.read()
print(text)
/usr/bin/squeue
从命令行或 Popen
.
它是否会失败,因为它需要一些关于正在执行 squeue
命令的 user/group 的信息,并且当 运行 通过 python 时,这些信息(不知何故)丢失了?还有什么可能导致这种情况?
subprocess.Popen
的第一个参数是字符串或字符串列表。如果它是单个字符串,它将被解释为文件名。这就是您收到错误的原因。
要传递字符串列表,它应该与 shell 将您的参数传递给进程的方式相匹配。标准的 shell 会用空格分割你的命令行,所以不要这样:
command = "/usr/bin/squeue --Format=username,jobid,name,timeleft"
你需要这个:
command = ["/usr/bin/squeue", "--Format=username,jobid,name,timeleft"]
正如您在评论中提到的那样,在“=”处拆分第二个参数只会混淆 squeue,然后它会看到两个参数。