forked from engineering/cloudservices
roll back issue with exec
parent
8ce060282e
commit
88198b2234
|
@ -32,26 +32,17 @@ export default class Util {
|
||||||
* @param options childProcess.ExecOptions
|
* @param options childProcess.ExecOptions
|
||||||
*/
|
*/
|
||||||
public async exec(command: string, options: childProcess.ExecOptions = {}): Promise<string> {
|
public async exec(command: string, options: childProcess.ExecOptions = {}): Promise<string> {
|
||||||
return new Promise((res, rej) => {
|
const ex = promisify(childProcess.exec);
|
||||||
let error = false;
|
let result: string;
|
||||||
let output = '';
|
try {
|
||||||
const writeFunction = (data: string|Buffer|Error) => {
|
const res = await ex(command, options);
|
||||||
if (data instanceof Error) error = true;
|
result = `${res.stdout}${res.stderr}`;
|
||||||
output += `${data}`;
|
} catch (err) {
|
||||||
};
|
return Promise.reject(new Error(`Command failed: ${err.cmd}\n${err.stderr}${err.stdout}`));
|
||||||
const cmd = childProcess.exec(command, options);
|
|
||||||
cmd.stdout.on('data', writeFunction);
|
|
||||||
cmd.stderr.on('data', writeFunction);
|
|
||||||
cmd.on('error', writeFunction);
|
|
||||||
cmd.once('close', (code, signal) => {
|
|
||||||
cmd.stdout.removeListener('data', writeFunction);
|
|
||||||
cmd.stderr.removeListener('data', writeFunction);
|
|
||||||
cmd.removeListener('error', writeFunction);
|
|
||||||
if (error) rej(output);
|
|
||||||
res(output);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a command
|
* Resolves a command
|
||||||
|
|
Loading…
Reference in New Issue