我正在尝试制作一个更新程序。我已经让主程序调用一个文件
updater.py
,该文件隐藏运行,因为我不想打扰主程序的执行。
然后,updater.py
文件通过连接到 GitHub 存储库并访问其中的
.txt
文件来检查更新是否可用,并检查主程序的
__version__
标识符是否低于最新版本。如果是,则程序调用
installer.py
,这需要是一个可见的进程才能与用户交互。在
main.py
中,我写了以下行:
Popen([sys.executable, 'updater.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Start the updater
这按预期工作,并且 updater.py
在后台运行。在
updater.py
中,我写道:
Popen([sys.executable, 'installer.py', latestVersion], stdin=subprocess.STDOUT, stdout=subprocess.STDOUT, stderr=subprocess.STDOUT, shell=True)
但是这不会运行installer.py
。相反,它给出了以下错误:
Traceback (most recent call last):
File "E:\Updated\updater.py", line 18, in <module>
Popen([executable, 'installer.py', latestVersion], stdin=subprocess.STDOUT, stdout=subprocess.STDOUT, stderr=subprocess.STDOUT, shell=True)
File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 992, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1361, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 9] Bad file descriptor
我不知道问题是什么,如果有人知道的话将会非常有帮助。
谢谢。
updater.py 你有:
Popen([sys.executable, 'installer.py', latestVersion], stdin=subprocess.STDOUT, stdout=subprocess.STDOUT, stderr=subprocess.STDOUT, shell=True
这应该是:
Popen([sys.executable, 'installer.py', latestVersion], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
但是,您似乎不需要 shell=True 参数。