Reputation: 19
My GUI is a python script launcher that I would like to create a new console window that handles the selected script. But I can't get subprocess.Popen to handle the arguments sent correctly. It runs the script from the GUI's Python environment and not the user selected environment even though the arguments list is populating correctly (eg. ['C:\\Python\\python.exe', '-i', 'C:\\Script\\testscript.py'].
def run_script(self):
# Create a list for arguments to be used in Popen
args = []
# Get the python path from config.ini
# Just assume this is C:\Python\python.exe
python_path = get_settings_value("Python_Path", "Default")
# Add the python path to the argument list
# Add '-i' to argument list, this will open an interactive python window
args.append(python_path)
args.append('-i')
# For every script selected, create a subprocess and run with argument list
for index in self.treeView_scripts.selectedIndexes():
# Only run if selected item is a file
if not self.tree_view_model.isDir(index):
# Get the full path to the script
script_path = os.path.abspath(self.tree_view_model.fileInfo(index))
# Append script path to the argument list, run subprocess, and remove the script path from the argument list
args.append(script_path)
subprocess.Popen(args, executable = sys.executable, creationflags = subprocess.CREATE_NEW_CONSOLE)
args.remove(script_path)
Upvotes: 0
Views: 101