dustybusty12
dustybusty12

Reputation: 107

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.

Upvotes: 0

Views: 10482

Answers (2)

itscarlayall
itscarlayall

Reputation: 166

Try to substitute:

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

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

Upvotes: 1

dustybusty12
dustybusty12

Reputation: 107

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)

Upvotes: 0

Related Questions