2015-08-28 176 views
0

我想运行一个python脚本。脚本的第一个步骤来运行正常,但在某些时候我有这样的消息:Python错误没有这样的文件或目录,但有文件

Traceback (most recent call last): 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 154, in <module> 
    iLaunchTRF.run()   
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 143, in run 
    self._launchTRF() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin/LaunchTRF.py", line 101, in _launchTRF 
    process = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
    File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ 
    errread, errwrite) 
    File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 
2015-08-28 12:38:05 - DetectTEFeatures - ERROR - ERROR when launching 'LaunchTRF.py -i TEs.60bp.fa -o TEs.60bp.fa.SSR.set -m 15 -c -v 0 > launchTRF.log' 
Traceback (most recent call last): 
    File "PASTEClassifier.py", line 199, in <module> 
    iLaunch.run()   
    File "PASTEClassifier.py", line 165, in run 
    iDF.run() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 185, in run 
    self._detectFeatures() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 204, in _detectFeatures 
    self._detectTRF() 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 267, in _detectTRF 
    self._logAndRaise("ERROR when launching '%s'" % cmd) 
    File "/home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/commons/tools/DetectTEFeatures.py", line 176, in _logAndRaise 
    raise Exception(errorMsg) 
Exception: ERROR when launching 'LaunchTRF.py -i TEs.60bp.fa -o TEs.60bp.fa.SSR.set -m 15 -c -v 0 > launchTRF.log' 

我看了一些其他职位有这种类型的错误,并基于这些,我看着如果LaunchTRF.py存在,它在那儿。实际上,当我仅运行LaunchTRF.py而没有任何选项时,我可以看到选项列表和帮助。我在想,丢失的文件是TEs.60bp.fa,但它也存在。

下面是在情况下,线98至103从LaunchTRF.py可能有助于:

def _launchTRF(self): 
     cmd = "trf %s 2 3 5 80 10 20 %d -h -d" % (self.inFileName, self.maxPeriod) 
     self._log.debug("Running : %s" % cmd) 
     process = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
     output = process.communicate() 
     self._log.debug("Output:\n%s" % output[0]) 

任何帮助是受欢迎的。

+0

你可以做一个打印(self.inFileName) 。确保该文件具有完整的路径名不只是blah.txt – FirebladeDan

回答

0
print(self.inFileName) 

应该等于

"C:\blah\something\test.txt" 

,如果它不只是在命令前加上名字

fullFile = "C:\blah\hooray\"+self.inFileName 

cmd = "trf %s 2 3 5 80 10 20 %d -h -d" % (fullFile, self.maxPeriod) 
0

这似乎与你的工作目录中的问题,也许是父脚本正在更改它,或者您正在从另一个目录执行父脚本。

,你可以做些什么来解决这个问题是通过传递一个额外的参数去工作目录改变popen方法:

subprocess.Popen('./LaunchTRF.py ...', cwd='/path/to/')

希望它可以帮助

+0

谢谢@Filipe我会尝试这个解决方案,我让你知道 – christian

+0

我修改subprocess.Popen process = subprocess.Popen(cmd.split(''), stdout = subprocess.PIPE,stderr = subprocess.PIPE,cwd =“/ home/chodar/Descargas/00.Comprimidos/REPET_linux-x64-2.2/bin /”)。没有工作,但我不是,如果我做得很好... – christian

+0

错误信息是否保持不变? – Filipe

相关问题