The execute command will loop and keep on reading the stdout and check for the return code and displays the output in real time.
(self, command, capture_output=False)
| 64 | requirements_file.write('\nfount_experiment_runner') |
| 65 | |
| 66 | def execute(self, command, capture_output=False): |
| 67 | """ |
| 68 | The execute command will loop and keep on reading the stdout and check for the return code |
| 69 | and displays the output in real time. |
| 70 | """ |
| 71 | |
| 72 | print("Running shell command: %s", command) |
| 73 | print(command) |
| 74 | if capture_output: |
| 75 | return subprocess.check_output(shlex.split(command)) |
| 76 | |
| 77 | process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) |
| 78 | |
| 79 | while True: |
| 80 | output = process.stdout.readline() |
| 81 | if output == b"" and process.poll() is not None: |
| 82 | break |
| 83 | if output: |
| 84 | print(output.strip()) |
| 85 | |
| 86 | return_code = process.poll() |
| 87 | |
| 88 | if return_code != 0: |
| 89 | print("Error running command %s - exit code: %s", command, return_code) |
| 90 | raise IOError("Shell Commmand Failed") |
| 91 | |
| 92 | return return_code |
| 93 | |
| 94 | def run_commands(self, commands): |
| 95 | for command in commands: |
no outgoing calls
no test coverage detected