【发布时间】:2015-09-22 03:35:31
【问题描述】:
我在 Windows 7 上编程,在我的一个 Python 项目中我需要调用 bedtools,它仅适用于 Windows 上的 Cygwin。我是 Cygwin 的新手,安装了默认版本 + bedtools 所需的一切,然后使用 Cygwin 通过使用 make 来安装 bedtools,如 installation instructions 中所述。
$ tar -zxvf BEDTools.tar.gz
$ cd BEDTools-<version>
$ make
当我使用 Cygwin 终端像下面这样手动调用它时,它可以正常工作并且输出文件包含正确的结果。
bedtools_exe_path intersect -a gene_bed_file -b snp_bed_file -wa -wb > output_file
但是当我在我的程序中使用subprocess.call 时,它似乎使用的是 Windows cmd 而不是 Cygwin,这不起作用。
arguments = [bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments)
导致没有输出文件并且返回码为3221225781。
arguments = [bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments, shell=True)
导致一个空的输出文件和3221225781的返回码。
cygwin_bash_path = 'D:/Cygwin/bin/bash.exe'
arguments = [cygwin_bash_path, bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments)
导致没有输出文件,返回码为126 和
D:/BEDTools/bin/bedtools.exe: D:/BEDTools/bin/bedtools.exe: cannot execute binary file
arguments = [cygwin_bash_path, bedtools_exe_path, 'intersect', '-a', gene_bed_file, '-b',
snp_bed_file, '-wa', '-wb', '>', output_file]
return_code = suprocess.call(arguments, shell=True)
导致一个空的输出文件,126 的返回码和
D:/BEDTools/bin/bedtools.exe: D:/BEDTools/bin/bedtools.exe: cannot execute binary file
有什么想法可以让它工作吗?
【问题讨论】:
-
试试pastebin.com/Q4DZcpA7。您不能将
'>'与 shell=False 一起使用。 126 表示权限问题或文件不可执行 -
如果你想将 stderr 重定向到文件也使用
check_call(arguments,stdout=f,stderr=sunprocess.STDOUT) -
感谢您的快速评论,不幸的是它产生了与上一个示例相同的结果(空输出文件,返回代码 126,bedtools.exe:无法执行二进制文件)。为什么我不能使用
'>'?编辑:添加stderr=subprocess:STDOUT时,输出文件不为空,而仅包含 bedtools.exe: cannot execute binary file 行。 -
你是从 cygwin 运行这个吗?您的输出文件是空的,因为代码错误所以输出是通过 stderr 而不是 stdout
-
我在 PyCharm 中运行代码。
标签: python windows cmd cygwin subprocess