Я пытаюсь использовать модуль подпроцесса, чтобы попытаться отправить инструкцию командной строки в командную строку.Вот соответствующий код:
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, чтобы увидеть, будет ли это иметь значение, и теперь он не распознает primer3_core как допустимую команду, хотя ядобавили его в ПУТЬ.
'primer3_core' is not recognized as an internal or external command,
operable program or batch file.
В настоящее время моя теория заключается в том, что вопрос о том, как кавычки обрабатываются командной строкой в Windows, может быть проблемой, поскольку они являются двойными кавычками в команде, но я не уверен.Любая помощь будет отличной!