microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
110558c0d2d536752a07e4f4310201a2e1731031

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/utils/node/childProcess.ts

75lines · modeblame

a31b007cunknown10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
3fb37ad5unknown10 years ago4import * as child_process from "child_process";
5import Q = require("q");
6
7export interface IExecResult {
8process: child_process.ChildProcess;
9outcome: Q.Promise<Buffer>;
10}
11
12interface IExecOptions {
13cwd?: string;
14stdio?: any;
15env?: any;
16encoding?: string;
17timeout?: number;
18maxBuffer?: number;
19killSignal?: string;
20}
21
22interface ISpawnOptions {
23cwd?: string;
24stdio?: any;
25env?: any;
26detached?: boolean;
27}
28
29interface ISpawnResult {
30stdin: any;
31stdout: any;
32stderr: any;
33outcome: Q.Promise<number>;
34}
35
36export class ChildProcess {
37public exec(command: string, options: IExecOptions = {}): IExecResult {
38let outcome = Q.defer<Buffer>();
39
40let execProcess = child_process.exec(command, options, (error: Error, stdout: Buffer, stderr: Buffer) => {
41if (error) {
42outcome.reject({ error: error, stderr: stderr});
43} else {
44outcome.resolve(stdout);
45}
46});
47
48return { process: execProcess, outcome: outcome.promise };
49}
50
51public execToString(command: string, options: IExecOptions = {}): Q.Promise<string> {
52return this.exec(command).outcome.then(stdout => stdout.toString());
53}
54
55public spawn(command: string, args?: string[], options: ISpawnOptions = {}): ISpawnResult {
56let outcome = Q.defer<number>();
57
58let spawnedProcess = child_process.spawn(command, args, options);
59spawnedProcess.once("error", (error: any) => {
60outcome.reject({ error: error });
61});
6c330a04dlebu10 years ago62spawnedProcess.once("exit", (code: number) => {
3fb37ad5unknown10 years ago63if (code === 0) {
64outcome.resolve(code);
6c330a04dlebu10 years ago65} else {
66outcome.reject({error: code});
3fb37ad5unknown10 years ago67}
68});
69
70return { stdin: spawnedProcess.stdin,
71stdout: spawnedProcess.stdout,
72stderr: spawnedProcess.stderr,
73outcome: outcome.promise };
74}
75}