我必须使用qsub (SGE)编写一个python脚本来提交作业。
我要执行的命令如下所示:
qsub -b y/usr/bin/l2prodfilein文件
如果L2prod是一个已编译的程序(二进制文件,这就是-b y选项的原因),而filein/fileout只是带有输入/输出文件名称的字符串。如果我打开一个shell并键入前面的行,一切都进行得很好。
在我的python程序中:
...
args=['qsub -b y ', L2prod, filein, fileout]
log.info('executing: '+' '.join(map(str,args)))
process=subprocess.Popen(args,shell=True)
...
etc.日志文件中的输出是:
INFO:job_submit:executing: qsub -b y /usr/bin/L2prod /-b/l1/20180414-222503_l1.txt/-b/l2/20180414-222503_l2.txt
查看日志,命令行似乎是正确的,但我得到了以下错误:
qsub:二进制作业所需的命令
也没有提交任何工作。
似乎"-b y“选项在.Popen()方法中被忽略了。我做错了什么?我以为shell=True选项会解决这个问题。
发布于 2019-03-20 13:34:14
必须将每个标志作为列表的单独字符串元素提供。第一行不一样。
# args=['qsub -b y ', L2prod, filein, fileout]
args=['qsub', '-b', 'y', L2prod, filein, fileout]
log.info('executing: '+' '.join(map(str,args)))
process=subprocess.Popen(args,shell=False)为什么要避免使用shell = True参数。
https://medium.com/python-pandemonium/a-trap-of-shell-true-in-the-subprocess-module-6db7fc66cdfd
https://stackoverflow.com/questions/55251388
复制相似问题