使用参数从 Python 脚本调用 windows .exe 文件

这是我正在尝试做的...


从网络下载一个 exe 静默安装 运行下载的 exe 并传递一个参数


我的代码是


import urllib.request

import shutil

import subprocess

import os

from os import system


url = "https://downloads.com/App.exe"

output_file = "C:\\files\App.exe"

with urllib.request.urlopen(url) as response, open(output_file, 'wb') as out_file:

    shutil.copyfileobj(response, out_file)


# Silent Install

subprocess.call("C:\\files\App.exe /SILENT ")



system("C:\\Program Files (x86)\\files\App.exe -ARG")

当我运行它时,它会下载 exe,然后安装 exe,但在尝试 exe 下载的文件时失败并出现此错误


'C:/Program' is not recognized as an internal or external command,

operable program or batch file.


慕尼黑的夜晚无繁华
浏览 184回答 2
2回答

MMTTMM

尝试替换:system("C:\\Program Files (x86)\\files\App.exe -ARG")经过: subprocess.call("C:\\Program Files (x86)\\files\App.exe -ARG")

慕的地8271018

使用以下解决import urllib.requestimport shutilimport subprocessimport osfrom os import systemurl = "https://downloads.com/App.exe"output_file = "C:\\files\App.exe"with urllib.request.urlopen(url) as response, open(output_file, 'wb') as out_file:    shutil.copyfileobj(response, out_file)# Silent Installsubprocess.call("C:\\files\App.exe /SILENT ")subprocess.call(['C:\\Program Files (x86)\\files\App.exe', '-ARG'], shell=True)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python