如何解决使用控制台从 pythonw 启动的 GUI 运行进程
我的 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 举报,一经查实,本站将立刻删除。