我想为我的项目创建一个自动更新程序,它从互联网上下载并安装一个文件。我已经完成了如何使用所需名称将文件下载到所需位置。我被卡住的地方是我如何安装文件。
到目前为止我写的代码:
from urllib.request import urlretrieve
import getpass
url = 'https://sourceforge.net/projects/artigence/files/latest/download'
print('File Downloading')
usrname = getpass.getuser()
destination = f'C:\\Users\\{usrname}\\Downloads\\download.exe'
download = urlretrieve(url, destination)
print('File downloaded')
并将文件下载到我的下载文件夹中。现在,如何使用 python 安装 .exe 文件?
您将需要使用该subprocess
模块来执行.exe
文件。
import subprocess
cmd = "{download location} batch.exe"
returned_value = subprocess.call(cmd, shell=True) # returns the exit code in unix
print('returned value:', returned_value)
我强烈建议不要为此使用pyautogui
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句