简体   繁体   English

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

[英]Call a windows .exe file from Python script with an argument

Here is what i am trying to do ... 这是我想要做的......

Download an exe from web Install it silently Run the downloaded exe and pass it an argument 从Web下载exe安静地安装它运行下载的exe并传递一个参数

The code I have is 我的代码是

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")

When i run it downloads the exe, installs the exe but then fails with this error when trying to exe the downloaded file 当我运行它下载exe,安装exe但在尝试exe下载文件时失败并出现此错误

'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

Resolved using the below 使用以下解决

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 ")

subprocess.call(['C:\\Program Files (x86)\\files\App.exe', '-ARG'], shell=True)

Try to substitute: 尝试替换:

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

by: subprocess.call("C:\\\\Program Files (x86)\\\\files\\App.exe -ARG") by: subprocess.call("C:\\\\Program Files (x86)\\\\files\\App.exe -ARG")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM