简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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