嗨我想通過導入命令module.py在python中執行bash命令我想我在這裏問同樣的問題。但是這一次它不起作用。 的腳本如下:命令模塊問題
#在/ usr/bin中/ Python的
import os,sys
import commands
import glob
path= '/home/xxx/nearline/bamfiles'
bamfiles = glob.glob(path + '/*.bam')
for bamfile in bamfiles:
fullpath = os.path.join(path,bamfile)
txtfile = commands.getoutput('/share/bin/samtools/samtools ' + 'view '+ fullpath)
line=txtfile.readlines()
print line
這samtools查看會產生(我認爲).txt文件
我得到了錯誤:
Traceback (most recent call last):
File "./try.py", line 12, in ?
txtfile = commands.getoutput('/share/bin/samtools/samtools ' + 'view '+ fullpath)
File "/usr/lib64/python2.4/commands.py", line 44, in getoutput
return getstatusoutput(cmd)[1]
File "/usr/lib64/python2.4/commands.py", line 54, in getstatusoutput
text = pipe.read()
SystemError: Objects/stringobject.c:3518: bad argument to internal function
似乎這是command.getoutput的問題
謝謝
這不會解決你所遇到的問題,但你將有一個未來的問題是,commands.getoutput()返回一個字符串,你調用readlines方法( ) 在上面。這將失敗,因爲readlines()是一個文件對象的操作。 – bschaffer13