我正在尝试使用Subprocess模块尝试将命令行指令发送到命令提示符。这是相关代码:
def get_primers(self):
if self.inputbool == False or self.outputbool == False:
tkinter.messagebox.showinfo('AUTOPRIMER', 'No input file and/or output destination detected!')
else:
if self.parambool == False:
outputlocation = '-output=' + '"' + self.output + 'primer3output.txt' + '"'
cmd = ['primer3_core', outputlocation, self.input]
cmd2 = 'primer3_core' + ' ' + outputlocation + ' ' + self.input
print(cmd2)
subprocess.call(cmd)
tkinter.messagebox.showinfo('AUTOPRIMER', 'Please check output file for desired content. If it is incorrect, please alter settings to achieve desired output.')
else: #parameters present
outputlocation = '-output=' + '"' + self.output + 'primer3output.txt' + '"'
p3filesettings = self.p3filestring + '"' + self.param + '"'
cmd = ['primer3_core', p3filesettings, outputlocation, self.input]
cmd2 = 'primer3_core' + ' ' + p3filesettings + ' ' + outputlocation + ' ' + self.input
print(cmd2)
subprocess.call(cmd)
tkinter.messagebox.showinfo('AUTOPRIMER', 'Please check output file for desired content. If it is incorrect, please alter settings to achieve desired output.')
命令的一般格式是对应用程序本身的调用,输出文件路径和输入文件路径。如果用户希望添加一个设置,则可能存在包含其他设置的文件路径。
示例:
primer3_core -p3_settings_file="C:/Users/mqian/Desktop/CGIProject/autoprimercode/output/test files/testingsettingscopy.txt" -output="C:/Users/mqian/Desktop/CGIProject/autoprimercode/output/test files/10-3/test2primer3output.txt
在命令提示符下键入该命令可以正常运行程序,但是当我尝试将这些组件作为列表甚至整个字符串传递给subprocess.call()函数时,得到的输出如下:>
C:\Users\mqian\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/mqian/Desktop/CGIProject/autoprimercode/windowsversion/workingwindowsautoprimer.py
primer3_core -p3_settings_file="C:/Users/mqian/Desktop/CGIProject/autoprimercode/output/test files/testingsettingscopy.txt" -output="C:/Users/mqian/Desktop/CGIProject/autoprimercode/output/test files/10-3/test2primer3output.txt" "C:/Users/mqian/Desktop/CGIProject/autoprimercode/output/test files/primerflowinput"
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\mqian\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:/Users/mqian/Desktop/CGIProject/autoprimercode/windowsversion/workingwindowsautoprimer.py", line 77, in get_primers
subprocess.Popen(cmd)
File "C:\Users\mqian\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\mqian\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
我尝试设置shell = True来查看是否会有所不同,现在即使将它添加到PATH中,它也无法将Primer3_core识别为有效命令。
'primer3_core' is not recognized as an internal or external command,
operable program or batch file.
当前,我的理论是Windows中命令提示符处理引号的方式可能是问题,因为它们是命令中的双引号,但我不确定。任何帮助都会很棒!