问题描述
我的 GUI 是一个 python 脚本启动器,我想创建一个新的控制台窗口来处理选定的脚本。但我无法让 subprocess.Popen 处理正确发送的参数。它从 GUI 的 Python 环境而不是用户选择的环境运行脚本,即使参数列表正确填充 (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)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)