|
12345678910111213141516171819202122232425262728293031323334 |
- import * as childProcess from 'child_process';
-
- export const spawn = (
- cwd: string,
- command: string,
- args: string[],
- parentProcess = process,
- ) => new Promise<string>((resolve, reject) => {
- let stdout = '';
- let stderr = '';
-
- const theChildProcess = childProcess.spawn(command, args, {
- cwd,
- });
-
- theChildProcess.stdout.on('data', (data) => {
- parentProcess.stdout.write(data);
- stdout += data;
- });
-
- theChildProcess.stderr.on('data', (data) => {
- parentProcess.stderr.write(data);
- stderr += data;
- });
-
- theChildProcess.on('close', (code) => {
- if (code !== 0) {
- reject(new Error(stderr));
- return;
- }
-
- resolve(stdout);
- })
- })
|