forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchildProc.ts
More file actions
24 lines (19 loc) · 921 Bytes
/
Copy pathchildProc.ts
File metadata and controls
24 lines (19 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
import * as path from 'path';
import * as fs from 'fs';
import * as child_process from 'child_process';
export function sendCommand(commandLine: string, cwd: string, includeErrorAsResponse:boolean = false): Promise<string> {
return new Promise<string>((resolve, reject) => {
child_process.exec(commandLine, { cwd: cwd }, (error, stdout, stderr) => {
if (includeErrorAsResponse){
return resolve(stdout + '\n' + stderr);
}
var hasErrors = (error && error.message.length > 0) || (stderr && stderr.length > 0);
if (hasErrors && (typeof stdout !== "string" || stdout.length === 0)) {
var errorMsg = (error && error.message) ? error.message : (stderr && stderr.length > 0 ? stderr + '' : "");
return reject(errorMsg);
}
resolve(stdout + '');
});
});
}