Change command used when running on Windows

Before this commit the string version of a command was used when running
on Windows. This changes it so the input - string or list of strings -
is passed directly.

In the case the input was a string, nothing changes.

In the case the input was a list, Python will internally build a command
string such that each element of the list is quoted correctly for
Windows exec call. We can't call that method directly because it's
considered an implementation detail, see below.

https://bugs.python.org/issue10838

An example of when this behavior is correct is if we build a command
line list and sys.executable needs to be quoted because it contains
spaces or something. Before this change the arguments would just be
joined with a space, which would not work.
This commit is contained in:
Paul O'Leary McCann 2022-09-02 13:23:36 +09:00
parent edfa32da47
commit 2fe360d7f3

View File

@ -974,7 +974,7 @@ def run_command(
cmd_list = command
cmd_str = " ".join(command)
try:
cmd_to_run = cmd_str if is_windows else cmd_list
cmd_to_run = command if is_windows else cmd_list
ret = subprocess.run(
cmd_to_run,
env=os.environ.copy(),