我遇到了一个问题,试图加入一些来自不同来源的Matlab代码,我真的不知道如何处理它。本质上,我有一些Python代码,用于从命令行调用的压缩算法,它本身使用子进程来运行并与编译成二进制的C++代码通信。在
Python中的函数(它是更大对象的一部分)如下所示:
def __extractRepeats(self, repeatClass):
process = subprocess.Popen(["./repeats1/repeats11", "-i", "-r"+repeatClass, "-n2", "-psol"],stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
process.stdin.write(' '.join(map(str,self.__concatenatedDAG)))
text_file = ''
while process.poll() is None:
output = process.communicate()[0].rstrip()
text_file += output
process.wait()
repeats=[]
firstLine = False
for line in text_file.splitlines():
if firstLine == False:
firstLine = True
continue
repeats.append(line.rstrip('\n'))
return repeats
通过将所有组件与Matlab进行集成,我决定通过将所有组件集成到一起来间接地减少系统的问题
^{pr2}$其中temp_脚本是可执行的,如下所示:
cd /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis
python Lexis.py -f i /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis/aabb.txt >> /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis/lexis_results.txt
现在我在Ubuntu16.04中运行这个,在这里从终端运行脚本。但是,从Matlab运行相同的脚本会给我错误
Traceback (most recent call last):
File "Lexis.py", line 762, in <module>
g.GLexis(quietLog, rFlag, functionFlag, costWeight)
File "Lexis.py", line 191, in GLexis
(maximumRepeatGainValue, selectedRepeatOccs) = self.__retreiveMaximumGainRepeat(normalRepeatType, CostFunction.EdgeCost)
File "Lexis.py", line 242, in __retreiveMaximumGainRepeat
repeats = self.__extractRepeats(repeatClass)
File "Lexis.py", line 302, in __extractRepeats
process.stdin.write(' '.join(map(str,self.__concatenatedDAG)))
IOError: [Errno 32] Broken pipe
或者错误
File "Lexis.py", line 251, in __retreiveMaximumGainRepeat
idx = map(int,repeatStats[2][1:-1].split(','))[0]
ValueError: invalid literal for int() with base 10: 'ersio'
我还不知道我什么时候得到的。在
repeatStats的相关片段是
repeats = self.__extractRepeats(repeatClass)
for r in repeats: #Extracting maximum repeat
repeatStats = r.split()
idx = map(int,repeatStats[2][1:-1].split(','))[0]
我真的不知道Matlab通过系统调用某个东西和直接从终端调用有什么不同,所以我不知道出了什么问题。在OSX10.11上,完全相同的代码可以工作。在
有人知道Matlab系统命令的内部工作原理吗?为什么它不能允许Python调用一个子进程?在
任何帮助都将不胜感激!在
假设你的repeatStats[2]是xersiox,10
然后repeatStats[2][1:-1]变成ersiox,1
然后repeatStats[2][1:-1].split(',')会产生一个列表['ersio','1']
正如您已经将整个列表传递给整个语句
^{pr2}$请尝试以下操作:
相关问题 更多 >
编程相关推荐