(command, background=False, timeout=60)
| 63 | |
| 64 | |
| 65 | def execute_bash_command(command, background=False, timeout=60): |
| 66 | print("Executing command: ", command) |
| 67 | if background: |
| 68 | subprocess.Popen( |
| 69 | command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 70 | ) |
| 71 | return |
| 72 | try: |
| 73 | child = pexpect.spawn( |
| 74 | "/bin/bash", ["-c", command + " 2>&1"], timeout=timeout |
| 75 | ) # Redirect stderr to stdout |
| 76 | child.expect(pexpect.EOF) |
| 77 | output = child.before.decode("utf-8") |
| 78 | except pexpect.TIMEOUT: |
| 79 | print("Command timed out") |
| 80 | child.terminate(force=True) |
| 81 | output = None |
| 82 | return output |
| 83 | |
| 84 | |
| 85 | def write_array_to_csv(arr, file_path): |
no test coverage detected