| 44 | |
| 45 | |
| 46 | def split_command(script_command, working_directory=None): |
| 47 | if ' ' in script_command: |
| 48 | if _is_file_path(script_command, working_directory): |
| 49 | args = [script_command] |
| 50 | else: |
| 51 | posix = not os_utils.is_win() |
| 52 | args = shlex.split(script_command, posix=posix) |
| 53 | |
| 54 | if not posix: |
| 55 | args = [string_utils.unwrap_quotes(arg) for arg in args] |
| 56 | else: |
| 57 | args = [script_command] |
| 58 | |
| 59 | script_path = file_utils.normalize_path(args[0], working_directory) |
| 60 | if (not os.path.isabs(script_path)) or (not os.path.exists(script_path)): |
| 61 | script_path = args[0] |
| 62 | |
| 63 | script_args = args[1:] |
| 64 | for i, body_arg in enumerate(script_args): |
| 65 | expanded = os.path.expanduser(body_arg) |
| 66 | if expanded != body_arg: |
| 67 | script_args[i] = expanded |
| 68 | |
| 69 | return [script_path] + script_args |
| 70 | |
| 71 | |
| 72 | def _is_file_path(script_command_with_whitespaces, working_directory): |