0

I faced unpleasant situation with silent installation of some program. I am not sure that they use any convention for installation flags with values but here what should be used for installation:

"path with spaces\setup.exe" -uninst -s -f2"path with spaces\uninstall.log"

you cannot use --f2="path with spaces\uninstall.log" or -f2="path with spaces\uninstall.log" or -f2 "path with spaces\uninstall.log"

so if I use in Python following:

command = [self.setup_exe, '-uninst', '-s', fr'-f2"{uninstall_log_file}"']

command that subprocess is executing (get from subprocess.list2cmdline(command)) is:

setup.exe" -uninst -s -f2\"some path\temp build 12\uninstall.log\"

basically slashes appear and installation is failing. Theoretically I can create my own string but the same provider for another executable provides another syntax which is more compatible with subprocess. I am wondering if it is possible to setup a list of arguments to satisfy reqs of installer?

15
  • How are you actually calling the command? It looks like you may be using shell=True when you shouldn't be. Commented Jun 19, 2020 at 13:14
  • @chepner, you are right, I am using shell=True. As far as I understood this is needed in case if I need to run command as elevated user (for example with PowerShell). Or will it work any case? Commented Jun 19, 2020 at 13:16
  • No, using shell=True just switches from executing the command directly to running a shell with a constructed argument to have the shell run the command for you. Commented Jun 19, 2020 at 13:18
  • here is how I call now: subprocess.call(command) Commented Jun 19, 2020 at 13:28
  • @chepner, now it is creating another layer of quotes: "-f2\"some path\uninstall.log\"" Commented Jun 19, 2020 at 13:29

1 Answer 1

0

If you run

"path with spaces\setup.exe" -uninst -s -f2"path with spaces\uninstall.log"

from the command line, the equivalent call to subprocess.call is

uninstall_log_file = r"path with spaces\uninstall.log"
command = [self.setup_exe, '-uninst', '-s', f'-f2{uninstall_log_file}']
subprocess.call(command)
Sign up to request clarification or add additional context in comments.

4 Comments

unfortunately this ill not work, I tried this already. If I put a path without spaces it will work. If I put a path with spaces then not since argument will look like "-f2path with spaces/log.log". So this does not work
I also tried this one: stackoverflow.com/questions/43022687/… however I assume difference in provider. Since there the argument will look like -f2=path with spaces. In my example from CMD equal sign is not allowed
I made a slight adjustment to the answer, making uninstall_log_file the raw string rather than the f-string that interpolates the value. I'm not sure if that will make a difference.
just performed the test. Unfortunately no. I executed subprocess with list but for check also ran list2cmdline. It is adding quotes around -f2 -> "-f2path". So installation fails. what is working but weird is: command = [f'"{self.setup_exe}"', '-uninst', '-s', fr'-f2"{uninstall_log_file}"'] command = " ".join(command) and then call subprocess with a string. Do you think it is possible to get the same using list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.