I am attempting to use the Subprocess module to try and send a command line instruction to the command prompt. Here is the relevant code:
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.')
The general format of the command is a call to the application itself, an output filepath, and an input filepath. There may be a filepath to a file that contains additional settings if the user desires to add one.
Example:
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
Typing that command into the command prompt runs the program properly, but when I try to pass the components as a list or even one whole string to the subprocess.call() function, the output I get is as follows:
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
I tried setting shell=True to see if that would make a difference, and now it is not recognizing primer3_core as a valid command even though I have added it to the PATH.
'primer3_core' is not recognized as an internal or external command,
operable program or batch file.
Currently, my theory is that the way quote marks are handled by the command prompt in windows might be the issue as their are double quotes in the command, but I'm not sure. Any help would be great!