* Starts a shell process and enables real-time streaming of stdout, stderr, and exit status. * * @param {string} command - The shell command to run (e.g., `"sh"`, `"ls -al"`). * @param {(type: 'stdout' | 'stderr' | 'exit', data: string) => void} onData - Callback that receives real-time out
(command, onData, alpine = false)
| 58 | * }); |
| 59 | */ |
| 60 | start(command, onData, alpine = false) { |
| 61 | return new Promise((resolve, reject) => { |
| 62 | let first = true; |
| 63 | exec( |
| 64 | async (message) => { |
| 65 | //console.log(message); |
| 66 | if (first) { |
| 67 | first = false; |
| 68 | await new Promise(resolve => setTimeout(resolve, 100)); |
| 69 | // First message is always the process UUID |
| 70 | resolve(message); |
| 71 | } else { |
| 72 | const match = message.match(/^([^:]+):(.*)$/); |
| 73 | if (match) { |
| 74 | const prefix = match[1]; // e.g. "stdout" |
| 75 | const content = match[2]; // output |
| 76 | onData(prefix, content); |
| 77 | } else { |
| 78 | onData("unknown", message); |
| 79 | } |
| 80 | } |
| 81 | }, |
| 82 | reject, |
| 83 | this.ExecutorType, |
| 84 | "start", |
| 85 | [command, String(alpine)] |
| 86 | ); |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Sends input to a running process's stdin. |
no test coverage detected