与''.join()相比,子进程调用提供的参数不正确

时间:2013-12-11 17:02:25

标签: python subprocess

当我运行命令

subprocess.call(['intersectBed','-u','-a',out_snv_filter,'-b',cds,'>',out_cds],shell=True)

我得到了解释器中报告的intersectBed的帮助菜单。

但是当我跑步时

>>> ' '.join(['intersectBed','-u','-a',out_snv_filter,'-b',cds,'>',out_cds])
'intersectBed -u -a test/test.out.snv.filter -b gencode7.cds.bed > test/test.out.cds'

$ intersectBed -u -a test/test.out.snv.filter -b gencode7.cds.bed > test/test.out.cds

程序正常运行。这有什么区别?

1 个答案:

答案 0 :(得分:2)

from subprocess import check_call

args = ['intersectBed','-u','-a',out_snv_filter,'-b',cds]
with open(out_cds, 'wb') as outfile:
    check_call(args, stdout=outfile)