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

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:

View File

@ -206,11 +206,11 @@ def configure_suite(config_file):
# Configure the parameters for bash tests
BT.Config.bin_dir = os.path.abspath(config['ENV']['exiv2_path'])
BT.Config.data_dir = os.path.abspath(config['paths']['data_path'])
BT.Config.tmp_dir = os.path.abspath(config['paths']['tmp_path'])
BT.Config.exiv2_ext = config['ENV']['binary_extension']
BT.Config.exiv2_http = config['ENV']['exiv2_http']
BT.Config.exiv2_port = int(config['ENV']['exiv2_port'])
BT.Config.data_dir = os.path.abspath(config['paths']['data_path'])
BT.Config.tmp_dir = os.path.abspath(config['paths']['tmp_path'])
# print(dict(config['ENV'])); exit(1) # for debug