Adjust the format of the command on Windows

This commit is contained in:
LeoHsiao
2020-09-03 22:29:20 +08:00
parent c7bf5dd12a
commit caa1acf197
2 changed files with 15 additions and 5 deletions
+13 -3
View File
@@ -365,14 +365,24 @@ def execute(cmd: str,
>>> execute('echo Hello')
>>> execute('exiv2 --help')
"""
# Check the input
args = shlex.split(cmd.format(**vars_dict), posix=os.name=='posix')
encoding = encoding or Config.encoding
# Check args
cmd = cmd.format(**vars_dict)
args = cmd.split(' ', maxsplit=1)
if args[0] in Config.bin_files:
args[0] = os.path.join(Config.bin_dir, args[0]) + Config.exiv2_ext
args = ' '.join(args)
if Config.system_name == 'Windows':
args = args.replace('\'', '\"')
else:
args = shlex.split(args, posix=os.name == 'posix')
# Check stdin
encoding = encoding or Config.encoding
if stdin:
if not isinstance(stdin, bytes):
stdin = str(stdin).encode(encoding)
# Check stdout
if redirect_stderr_to_stdout:
stderr_to = subprocess.STDOUT
else: