(options: {
exec: ExecFunction;
cmd: string;
args?: string[];
cwd?: string;
env?: NodeJS.ProcessEnv;
stdin?: Buffer | fs.ReadStream | Event<string>;
output: Log;
print?: boolean | 'continuous' | 'onerror';
})
| 80 | } |
| 81 | |
| 82 | export async function runCommandNoPty(options: { |
| 83 | exec: ExecFunction; |
| 84 | cmd: string; |
| 85 | args?: string[]; |
| 86 | cwd?: string; |
| 87 | env?: NodeJS.ProcessEnv; |
| 88 | stdin?: Buffer | fs.ReadStream | Event<string>; |
| 89 | output: Log; |
| 90 | print?: boolean | 'continuous' | 'onerror'; |
| 91 | }) { |
| 92 | const { exec, cmd, args, cwd, env, stdin, output, print } = options; |
| 93 | |
| 94 | const p = await exec({ |
| 95 | cmd, |
| 96 | args, |
| 97 | cwd, |
| 98 | env, |
| 99 | output, |
| 100 | }); |
| 101 | |
| 102 | return new Promise<{ stdout: Buffer; stderr: Buffer }>((resolve, reject) => { |
| 103 | const stdout: Buffer[] = []; |
| 104 | const stderr: Buffer[] = []; |
| 105 | |
| 106 | const stdoutDecoder = print === 'continuous' ? new StringDecoder() : undefined; |
| 107 | p.stdout.on('data', (chunk: Buffer) => { |
| 108 | stdout.push(chunk); |
| 109 | if (print === 'continuous') { |
| 110 | output.write(stdoutDecoder!.write(chunk)); |
| 111 | } |
| 112 | }); |
| 113 | p.stdout.on('error', (err: any) => { |
| 114 | // ENOTCONN seen with missing executable in addition to ENOENT on child_process. |
| 115 | if (err?.code !== 'ENOTCONN') { |
| 116 | throw err; |
| 117 | } |
| 118 | }); |
| 119 | const stderrDecoder = print === 'continuous' ? new StringDecoder() : undefined; |
| 120 | p.stderr.on('data', (chunk: Buffer) => { |
| 121 | stderr.push(chunk); |
| 122 | if (print === 'continuous') { |
| 123 | output.write(toErrorText(stderrDecoder!.write(chunk))); |
| 124 | } |
| 125 | }); |
| 126 | p.stderr.on('error', (err: any) => { |
| 127 | // ENOTCONN seen with missing executable in addition to ENOENT on child_process. |
| 128 | if (err?.code !== 'ENOTCONN') { |
| 129 | throw err; |
| 130 | } |
| 131 | }); |
| 132 | const subs: Disposable[] = []; |
| 133 | p.exit.then(({ code, signal }) => { |
| 134 | try { |
| 135 | const failed = !!code || !!signal; |
| 136 | subs.forEach(sub => sub.dispose()); |
| 137 | const stdoutBuf = Buffer.concat(stdout); |
| 138 | const stderrBuf = Buffer.concat(stderr); |
| 139 | if (print === true || (failed && print === 'onerror')) { |
no test coverage detected