SLURM squeue format参数从失败子流程.Popen

2024-10-01 02:29:55 发布

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

我试图从python脚本调用SLURM squeue。指挥部

/usr/bin/squeue --Format=username,jobid,name,timeleft

从命令行可以正常工作,但在^{}中失败:

    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:

^{pr2}$

/usr/bin/squeue从命令行或Popen都可以正常工作。在

它是否会失败,因为它需要有关执行squeue命令的用户/组的一些信息,而这些信息在通过python运行时(不知何故)丢失了?还有什么原因?在


Tags: 命令行nameformatbinusrusernamefilesubprocess
1条回答
网友
1楼 · 发布于 2024-10-01 02:29:55

subprocess.Popen的第一个参数要么是字符串,要么是字符串列表。如果它是一个字符串,它将被解释为一个文件名。这就是错误的原因。 要传递字符串列表,它应该与shell将参数传递给进程的方式相匹配。一个标准的shell将用空格分隔命令行,而不是这样:

command = "/usr/bin/squeue  Format=username,jobid,name,timeleft"

你需要这个:

^{pr2}$

正如您在评论中提到的那样,在“=”处拆分第二个参数会混淆squeue,然后它会看到两个参数。在

相关问题 更多 >