Creates a subprocess using supplied command and arguments. Will not return until the process completes running :param command: The command (full path) to execute :param args: a tuple of arguments :return: string with the output from the command
(command, *args)
| 66 | |
| 67 | |
| 68 | def execute_command_blocking(command, *args): |
| 69 | """ |
| 70 | Creates a subprocess using supplied command and arguments. |
| 71 | Will not return until the process completes running |
| 72 | :param command: The command (full path) to execute |
| 73 | :param args: a tuple of arguments |
| 74 | :return: string with the output from the command |
| 75 | |
| 76 | """ |
| 77 | print(f'Executing {command} with {args}') |
| 78 | expanded_args = [a for a in args] |
| 79 | try: |
| 80 | sp = subprocess.Popen([command, expanded_args], shell=True, |
| 81 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 82 | out, err = sp.communicate() |
| 83 | if out: |
| 84 | print(out.decode("utf-8")) |
| 85 | if err: |
| 86 | print(err.decode("utf-8")) |
| 87 | except Exception as e: |
| 88 | sg.Print(f'execute got exception {e}') |
| 89 | out = '' |
| 90 | return out |
| 91 | |
| 92 | |
| 93 | # ----------------------------- When program is first started ----------------------------- |