【发布时间】:2014-03-14 09:45:38
【问题描述】:
我正在编写一个 python 代码,它使用了一些只能从我的 Unix 终端(Windows 7 操作系统,使用 putty 终端)访问的程序为了我。
这是代码
#written in Py 2.7
from subprocess import call
subject = open ('test_file1', 'r')
target =open ('test_file2', 'r')
output = open ('output_test.bla8', 'w')
call(['blat', '-prot', '-minScore=0', '-stepSize=5', '-repMatch=2253', '-minIdentity=0', '-out=blast8', subject, target, output])
subject.close()
target.close()
output.close()
我收到的错误是这样的:
TypeError: execv() arg 2 must contain only strings
所以有点解释,“blat”是我正在调用的程序,所有 -flags 都是我想传递给 blat 程序的参数,最后三个语句也是我需要进入程序的参数,但是他们实际上为程序指定要读/写的文件。
如果不使用'subprocess.call',有没有办法将参数值传递给实际上是文件的shell命令?当然有一种简单的方法可以做到这一点,作为我的初学者,我只是不知道。顺便说一下,我看过 subprocess 文档,但作为一个新手,我仍然无法完全理解 http://docs.python.org/2/library/subprocess.html#subprocess.call
谢谢!!!
【问题讨论】:
-
blat是用来获取文件名还是句柄?我敢打赌,问题在于您将命令组件列表中的文件对象传递给call,并且它只需要字符串。您在寻找stdin和stdoutkwargs 吗? -
是的,你的预感是正确的。调用函数将只接受字符串。我认为不可能做我正在尝试的事情。我通过创建我需要的输入文件列表然后通过索引查找将它们提供给 call() 来解决这个问题(代码如下作为新答案)。谢谢,塞拉斯!
标签: python shell variables unix subprocess