spawn-rx 2.0.12 → 4.0.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierrc +4 -0
- package/CODE_OF_CONDUCT.md +50 -50
- package/COPYING +7 -7
- package/README.md +187 -187
- package/build.cmd +1 -1
- package/build.sh +2 -2
- package/esdoc.json +26 -26
- package/eslint.config.mjs +88 -0
- package/lib/src/index.d.ts +84 -88
- package/lib/src/index.js +336 -316
- package/lib/src/index.js.map +1 -1
- package/package.json +28 -21
- package/src/ambient.d.ts +1 -1
- package/src/index.ts +405 -341
- package/test/asserttest.ts +16 -15
- package/test/spawn.ts +139 -102
- package/test/support.ts +15 -14
- package/tsconfig.json +25 -29
- package/.npmignore +0 -3
- package/.travis.yml +0 -24
- package/appveyor.yml +0 -21
- package/lib/index.js +0 -352
- package/tslint.json +0 -38
package/src/index.ts
CHANGED
@@ -1,341 +1,405 @@
|
|
1
|
-
|
2
|
-
import * as
|
3
|
-
import * as
|
4
|
-
import * as
|
5
|
-
|
6
|
-
|
7
|
-
import
|
8
|
-
import
|
9
|
-
import
|
10
|
-
import {
|
11
|
-
import
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
37
|
-
|
38
|
-
|
39
|
-
*
|
40
|
-
*
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
*
|
77
|
-
*
|
78
|
-
*
|
79
|
-
*
|
80
|
-
*
|
81
|
-
*
|
82
|
-
*
|
83
|
-
*
|
84
|
-
* @
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
//
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
*
|
152
|
-
*
|
153
|
-
*
|
154
|
-
*
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
}
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
}
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
}
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
import * as path from "path";
|
3
|
+
import * as net from "net";
|
4
|
+
import * as sfs from "fs";
|
5
|
+
import * as assign from "lodash.assign";
|
6
|
+
|
7
|
+
import type { Observer, Subject } from "rxjs";
|
8
|
+
import { Observable, Subscription, AsyncSubject, of, merge } from "rxjs";
|
9
|
+
import { map, reduce } from "rxjs/operators";
|
10
|
+
import { spawn as spawnOg } from "child_process";
|
11
|
+
import Debug from "debug";
|
12
|
+
|
13
|
+
const isWindows = process.platform === "win32";
|
14
|
+
|
15
|
+
const d = Debug("spawn-rx"); // tslint:disable-line:no-var-requires
|
16
|
+
|
17
|
+
/**
|
18
|
+
* stat a file but don't throw if it doesn't exist
|
19
|
+
*
|
20
|
+
* @param {string} file The path to a file
|
21
|
+
* @return {Stats} The stats structure
|
22
|
+
*
|
23
|
+
* @private
|
24
|
+
*/
|
25
|
+
function statSyncNoException(file: string): sfs.Stats | null {
|
26
|
+
try {
|
27
|
+
return sfs.statSync(file);
|
28
|
+
} catch {
|
29
|
+
return null;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Search PATH to see if a file exists in any of the path folders.
|
35
|
+
*
|
36
|
+
* @param {string} exe The file to search for
|
37
|
+
* @return {string} A fully qualified path, or the original path if nothing
|
38
|
+
* is found
|
39
|
+
*
|
40
|
+
* @private
|
41
|
+
*/
|
42
|
+
function runDownPath(exe: string): string {
|
43
|
+
// NB: Windows won't search PATH looking for executables in spawn like
|
44
|
+
// Posix does
|
45
|
+
|
46
|
+
// Files with any directory path don't get this applied
|
47
|
+
if (exe.match(/[\\/]/)) {
|
48
|
+
d("Path has slash in directory, bailing");
|
49
|
+
return exe;
|
50
|
+
}
|
51
|
+
|
52
|
+
const target = path.join(".", exe);
|
53
|
+
if (statSyncNoException(target)) {
|
54
|
+
d(`Found executable in currect directory: ${target}`);
|
55
|
+
return target;
|
56
|
+
}
|
57
|
+
|
58
|
+
const haystack = process.env.PATH!.split(isWindows ? ";" : ":");
|
59
|
+
for (const p of haystack) {
|
60
|
+
const needle = path.join(p, exe);
|
61
|
+
if (statSyncNoException(needle)) {
|
62
|
+
return needle;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
d("Failed to find executable anywhere in path");
|
67
|
+
return exe;
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Finds the actual executable and parameters to run on Windows. This method
|
72
|
+
* mimics the POSIX behavior of being able to run scripts as executables by
|
73
|
+
* replacing the passed-in executable with the script runner, for PowerShell,
|
74
|
+
* CMD, and node scripts.
|
75
|
+
*
|
76
|
+
* This method also does the work of running down PATH, which spawn on Windows
|
77
|
+
* also doesn't do, unlike on POSIX.
|
78
|
+
*
|
79
|
+
* @param {string} exe The executable to run
|
80
|
+
* @param {Array<string>} args The arguments to run
|
81
|
+
*
|
82
|
+
* @return {Object} The cmd and args to run
|
83
|
+
* @property {string} cmd The command to pass to spawn
|
84
|
+
* @property {Array<string>} args The arguments to pass to spawn
|
85
|
+
*/
|
86
|
+
export function findActualExecutable(
|
87
|
+
exe: string,
|
88
|
+
args: Array<string>,
|
89
|
+
): {
|
90
|
+
cmd: string;
|
91
|
+
args: Array<string>;
|
92
|
+
} {
|
93
|
+
// POSIX can just execute scripts directly, no need for silly goosery
|
94
|
+
if (process.platform !== "win32") {
|
95
|
+
return { cmd: runDownPath(exe), args: args };
|
96
|
+
}
|
97
|
+
|
98
|
+
if (!sfs.existsSync(exe)) {
|
99
|
+
// NB: When you write something like `surf-client ... -- surf-build` on Windows,
|
100
|
+
// a shell would normally convert that to surf-build.cmd, but since it's passed
|
101
|
+
// in as an argument, it doesn't happen
|
102
|
+
const possibleExts = [".exe", ".bat", ".cmd", ".ps1"];
|
103
|
+
for (const ext of possibleExts) {
|
104
|
+
const possibleFullPath = runDownPath(`${exe}${ext}`);
|
105
|
+
|
106
|
+
if (sfs.existsSync(possibleFullPath)) {
|
107
|
+
return findActualExecutable(possibleFullPath, args);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
if (exe.match(/\.ps1$/i)) {
|
113
|
+
const cmd = path.join(
|
114
|
+
process.env.SYSTEMROOT!,
|
115
|
+
"System32",
|
116
|
+
"WindowsPowerShell",
|
117
|
+
"v1.0",
|
118
|
+
"PowerShell.exe",
|
119
|
+
);
|
120
|
+
const psargs = [
|
121
|
+
"-ExecutionPolicy",
|
122
|
+
"Unrestricted",
|
123
|
+
"-NoLogo",
|
124
|
+
"-NonInteractive",
|
125
|
+
"-File",
|
126
|
+
exe,
|
127
|
+
];
|
128
|
+
|
129
|
+
return { cmd: cmd, args: psargs.concat(args) };
|
130
|
+
}
|
131
|
+
|
132
|
+
if (exe.match(/\.(bat|cmd)$/i)) {
|
133
|
+
const cmd = path.join(process.env.SYSTEMROOT!, "System32", "cmd.exe");
|
134
|
+
const cmdArgs = ["/C", exe, ...args];
|
135
|
+
|
136
|
+
return { cmd: cmd, args: cmdArgs };
|
137
|
+
}
|
138
|
+
|
139
|
+
if (exe.match(/\.(js)$/i)) {
|
140
|
+
const cmd = process.execPath;
|
141
|
+
const nodeArgs = [exe];
|
142
|
+
|
143
|
+
return { cmd: cmd, args: nodeArgs.concat(args) };
|
144
|
+
}
|
145
|
+
|
146
|
+
// Dunno lol
|
147
|
+
return { cmd: exe, args: args };
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Spawns a process but detached from the current process. The process is put
|
152
|
+
* into its own Process Group that can be killed by unsubscribing from the
|
153
|
+
* return Observable.
|
154
|
+
*
|
155
|
+
* @param {string} exe The executable to run
|
156
|
+
* @param {Array<string>} params The parameters to pass to the child
|
157
|
+
* @param {Object} opts Options to pass to spawn.
|
158
|
+
*
|
159
|
+
* @return {Observable<string>} Returns an Observable that when subscribed
|
160
|
+
* to, will create a detached process. The
|
161
|
+
* process output will be streamed to this
|
162
|
+
* Observable, and if unsubscribed from, the
|
163
|
+
* process will be terminated early. If the
|
164
|
+
* process terminates with a non-zero value,
|
165
|
+
* the Observable will terminate with onError.
|
166
|
+
*/
|
167
|
+
export function spawnDetached(
|
168
|
+
exe: string,
|
169
|
+
params: Array<string>,
|
170
|
+
opts: any = null,
|
171
|
+
): Observable<string> {
|
172
|
+
const { cmd, args } = findActualExecutable(exe, params);
|
173
|
+
|
174
|
+
if (!isWindows) {
|
175
|
+
return spawn(cmd, args, assign({}, opts || {}, { detached: true }));
|
176
|
+
}
|
177
|
+
|
178
|
+
const newParams = [cmd].concat(args);
|
179
|
+
|
180
|
+
const target = path.join(
|
181
|
+
__dirname,
|
182
|
+
"..",
|
183
|
+
"..",
|
184
|
+
"vendor",
|
185
|
+
"jobber",
|
186
|
+
"Jobber.exe",
|
187
|
+
);
|
188
|
+
const options = assign({}, opts || {}, { detached: true, jobber: true });
|
189
|
+
|
190
|
+
d(`spawnDetached: ${target}, ${newParams}`);
|
191
|
+
return spawn(target, newParams, options);
|
192
|
+
}
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Spawns a process attached as a child of the current process.
|
196
|
+
*
|
197
|
+
* @param {string} exe The executable to run
|
198
|
+
* @param {Array<string>} params The parameters to pass to the child
|
199
|
+
* @param {Object} opts Options to pass to spawn.
|
200
|
+
*
|
201
|
+
* @return {Observable<string>} Returns an Observable that when subscribed
|
202
|
+
* to, will create a child process. The
|
203
|
+
* process output will be streamed to this
|
204
|
+
* Observable, and if unsubscribed from, the
|
205
|
+
* process will be terminated early. If the
|
206
|
+
* process terminates with a non-zero value,
|
207
|
+
* the Observable will terminate with onError.
|
208
|
+
*/
|
209
|
+
|
210
|
+
export function spawn<T = string>(
|
211
|
+
exe: string,
|
212
|
+
params: Array<string> = [],
|
213
|
+
opts: any = null,
|
214
|
+
): Observable<T> {
|
215
|
+
opts = opts || {};
|
216
|
+
const spawnObs = Observable.create(
|
217
|
+
(
|
218
|
+
subj: Observer<{
|
219
|
+
source: any;
|
220
|
+
text: any;
|
221
|
+
}>,
|
222
|
+
) => {
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
224
|
+
const { _, ...optsWithoutStdIn } = opts;
|
225
|
+
const { cmd, args } = findActualExecutable(exe, params);
|
226
|
+
d(
|
227
|
+
`spawning process: ${cmd} ${args.join()}, ${JSON.stringify(
|
228
|
+
optsWithoutStdIn,
|
229
|
+
)}`,
|
230
|
+
);
|
231
|
+
const origOpts = assign({}, optsWithoutStdIn);
|
232
|
+
if ("jobber" in origOpts) {
|
233
|
+
delete origOpts.jobber;
|
234
|
+
}
|
235
|
+
if ("split" in origOpts) {
|
236
|
+
delete origOpts.split;
|
237
|
+
}
|
238
|
+
|
239
|
+
const proc = spawnOg(cmd, args, origOpts);
|
240
|
+
|
241
|
+
const bufHandler = (source: string) => (b: string | Buffer) => {
|
242
|
+
if (b.length < 1) {
|
243
|
+
return;
|
244
|
+
}
|
245
|
+
let chunk = "<< String sent back was too long >>";
|
246
|
+
try {
|
247
|
+
if (typeof b === "string") {
|
248
|
+
chunk = b.toString();
|
249
|
+
} else {
|
250
|
+
chunk = b.toString(origOpts.encoding || "utf8");
|
251
|
+
}
|
252
|
+
} catch {
|
253
|
+
chunk = `<< Lost chunk of process output for ${exe} - length was ${b.length}>>`;
|
254
|
+
}
|
255
|
+
|
256
|
+
subj.next({ source: source, text: chunk });
|
257
|
+
};
|
258
|
+
|
259
|
+
const ret = new Subscription();
|
260
|
+
|
261
|
+
if (opts.stdin) {
|
262
|
+
if (proc.stdin) {
|
263
|
+
ret.add(
|
264
|
+
opts.stdin.subscribe(
|
265
|
+
(x: any) => proc.stdin.write(x),
|
266
|
+
subj.error.bind(subj),
|
267
|
+
() => proc.stdin.end(),
|
268
|
+
),
|
269
|
+
);
|
270
|
+
} else {
|
271
|
+
subj.error(
|
272
|
+
new Error(
|
273
|
+
`opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required`,
|
274
|
+
),
|
275
|
+
);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
let stderrCompleted: Subject<boolean> | Observable<boolean> | null = null;
|
280
|
+
let stdoutCompleted: Subject<boolean> | Observable<boolean> | null = null;
|
281
|
+
let noClose = false;
|
282
|
+
|
283
|
+
if (proc.stdout) {
|
284
|
+
stdoutCompleted = new AsyncSubject<boolean>();
|
285
|
+
proc.stdout.on("data", bufHandler("stdout"));
|
286
|
+
proc.stdout.on("close", () => {
|
287
|
+
(stdoutCompleted! as Subject<boolean>).next(true);
|
288
|
+
(stdoutCompleted! as Subject<boolean>).complete();
|
289
|
+
});
|
290
|
+
} else {
|
291
|
+
stdoutCompleted = of(true);
|
292
|
+
}
|
293
|
+
|
294
|
+
if (proc.stderr) {
|
295
|
+
stderrCompleted = new AsyncSubject<boolean>();
|
296
|
+
proc.stderr.on("data", bufHandler("stderr"));
|
297
|
+
proc.stderr.on("close", () => {
|
298
|
+
(stderrCompleted! as Subject<boolean>).next(true);
|
299
|
+
(stderrCompleted! as Subject<boolean>).complete();
|
300
|
+
});
|
301
|
+
} else {
|
302
|
+
stderrCompleted = of(true);
|
303
|
+
}
|
304
|
+
|
305
|
+
proc.on("error", (e: Error) => {
|
306
|
+
noClose = true;
|
307
|
+
subj.error(e);
|
308
|
+
});
|
309
|
+
|
310
|
+
proc.on("close", (code: number) => {
|
311
|
+
noClose = true;
|
312
|
+
const pipesClosed = merge(stdoutCompleted!, stderrCompleted!).pipe(
|
313
|
+
reduce((acc) => acc, true),
|
314
|
+
);
|
315
|
+
|
316
|
+
if (code === 0) {
|
317
|
+
pipesClosed.subscribe(() => subj.complete());
|
318
|
+
} else {
|
319
|
+
pipesClosed.subscribe(() => {
|
320
|
+
const e: any = new Error(`Failed with exit code: ${code}`);
|
321
|
+
e.exitCode = code;
|
322
|
+
|
323
|
+
subj.error(e);
|
324
|
+
});
|
325
|
+
}
|
326
|
+
});
|
327
|
+
|
328
|
+
ret.add(
|
329
|
+
new Subscription(() => {
|
330
|
+
if (noClose) {
|
331
|
+
return;
|
332
|
+
}
|
333
|
+
|
334
|
+
d(`Killing process: ${cmd} ${args.join()}`);
|
335
|
+
if (opts.jobber) {
|
336
|
+
// NB: Connecting to Jobber's named pipe will kill it
|
337
|
+
net.connect(`\\\\.\\pipe\\jobber-${proc.pid}`);
|
338
|
+
setTimeout(() => proc.kill(), 5 * 1000);
|
339
|
+
} else {
|
340
|
+
proc.kill();
|
341
|
+
}
|
342
|
+
}),
|
343
|
+
);
|
344
|
+
|
345
|
+
return ret;
|
346
|
+
},
|
347
|
+
);
|
348
|
+
|
349
|
+
return opts.split ? spawnObs : spawnObs.pipe(map((x: any) => x?.text));
|
350
|
+
}
|
351
|
+
|
352
|
+
function wrapObservableInPromise<T>(obs: Observable<T>) {
|
353
|
+
return new Promise<string>((res, rej) => {
|
354
|
+
let out = "";
|
355
|
+
|
356
|
+
obs.subscribe(
|
357
|
+
(x) => (out += x),
|
358
|
+
(e) => rej(new Error(`${out}\n${e.message}`)),
|
359
|
+
() => res(out),
|
360
|
+
);
|
361
|
+
});
|
362
|
+
}
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Spawns a process but detached from the current process. The process is put
|
366
|
+
* into its own Process Group.
|
367
|
+
*
|
368
|
+
* @param {string} exe The executable to run
|
369
|
+
* @param {Array<string>} params The parameters to pass to the child
|
370
|
+
* @param {Object} opts Options to pass to spawn.
|
371
|
+
*
|
372
|
+
* @return {Promise<string>} Returns an Promise that represents a detached
|
373
|
+
* process. The value returned is the process
|
374
|
+
* output. If the process terminates with a
|
375
|
+
* non-zero value, the Promise will resolve with
|
376
|
+
* an Error.
|
377
|
+
*/
|
378
|
+
export function spawnDetachedPromise(
|
379
|
+
exe: string,
|
380
|
+
params: Array<string>,
|
381
|
+
opts: any = null,
|
382
|
+
): Promise<string> {
|
383
|
+
return wrapObservableInPromise<string>(spawnDetached(exe, params, opts));
|
384
|
+
}
|
385
|
+
|
386
|
+
/**
|
387
|
+
* Spawns a process as a child process.
|
388
|
+
*
|
389
|
+
* @param {string} exe The executable to run
|
390
|
+
* @param {Array<string>} params The parameters to pass to the child
|
391
|
+
* @param {Object} opts Options to pass to spawn.
|
392
|
+
*
|
393
|
+
* @return {Promise<string>} Returns an Promise that represents a child
|
394
|
+
* process. The value returned is the process
|
395
|
+
* output. If the process terminates with a
|
396
|
+
* non-zero value, the Promise will resolve with
|
397
|
+
* an Error.
|
398
|
+
*/
|
399
|
+
export function spawnPromise(
|
400
|
+
exe: string,
|
401
|
+
params: Array<string>,
|
402
|
+
opts: any = null,
|
403
|
+
): Promise<string> {
|
404
|
+
return wrapObservableInPromise<string>(spawn(exe, params, opts));
|
405
|
+
}
|