spawn-rx 2.0.11 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.js +352 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +13 -3
- package/lib/src/index.js.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +9 -8
- package/tsconfig.json +1 -4
package/lib/index.js
ADDED
@@ -0,0 +1,352 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.findActualExecutable = findActualExecutable;
|
7
|
+
exports.spawnDetached = spawnDetached;
|
8
|
+
exports.spawn = spawn;
|
9
|
+
exports.spawnDetachedPromise = spawnDetachedPromise;
|
10
|
+
exports.spawnPromise = spawnPromise;
|
11
|
+
|
12
|
+
var _path = require('path');
|
13
|
+
|
14
|
+
var _path2 = _interopRequireDefault(_path);
|
15
|
+
|
16
|
+
var _net = require('net');
|
17
|
+
|
18
|
+
var _net2 = _interopRequireDefault(_net);
|
19
|
+
|
20
|
+
var _fs = require('fs');
|
21
|
+
|
22
|
+
var _fs2 = _interopRequireDefault(_fs);
|
23
|
+
|
24
|
+
require('rxjs/add/observable/of');
|
25
|
+
|
26
|
+
require('rxjs/add/observable/merge');
|
27
|
+
|
28
|
+
require('rxjs/add/operator/pluck');
|
29
|
+
|
30
|
+
require('rxjs/add/operator/reduce');
|
31
|
+
|
32
|
+
var _Observable = require('rxjs/Observable');
|
33
|
+
|
34
|
+
var _Subscription = require('rxjs/Subscription');
|
35
|
+
|
36
|
+
var _AsyncSubject = require('rxjs/AsyncSubject');
|
37
|
+
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
39
|
+
|
40
|
+
const spawnOg = require('child_process').spawn;
|
41
|
+
const isWindows = process.platform === 'win32';
|
42
|
+
|
43
|
+
const d = require('debug')('spawn-rx');
|
44
|
+
|
45
|
+
/**
|
46
|
+
* stat a file but don't throw if it doesn't exist
|
47
|
+
*
|
48
|
+
* @param {string} file The path to a file
|
49
|
+
* @return {Stats} The stats structure
|
50
|
+
*
|
51
|
+
* @private
|
52
|
+
*/
|
53
|
+
function statSyncNoException(file) {
|
54
|
+
try {
|
55
|
+
return _fs2.default.statSync(file);
|
56
|
+
} catch (e) {
|
57
|
+
return null;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Search PATH to see if a file exists in any of the path folders.
|
63
|
+
*
|
64
|
+
* @param {string} exe The file to search for
|
65
|
+
* @return {string} A fully qualified path, or the original path if nothing
|
66
|
+
* is found
|
67
|
+
*
|
68
|
+
* @private
|
69
|
+
*/
|
70
|
+
function runDownPath(exe) {
|
71
|
+
// NB: Windows won't search PATH looking for executables in spawn like
|
72
|
+
// Posix does
|
73
|
+
|
74
|
+
// Files with any directory path don't get this applied
|
75
|
+
if (exe.match(/[\\\/]/)) {
|
76
|
+
d('Path has slash in directory, bailing');
|
77
|
+
return exe;
|
78
|
+
}
|
79
|
+
|
80
|
+
let target = _path2.default.join('.', exe);
|
81
|
+
if (statSyncNoException(target)) {
|
82
|
+
d(`Found executable in currect directory: ${ target }`);
|
83
|
+
return target;
|
84
|
+
}
|
85
|
+
|
86
|
+
let haystack = process.env.PATH.split(isWindows ? ';' : ':');
|
87
|
+
for (let p of haystack) {
|
88
|
+
let needle = _path2.default.join(p, exe);
|
89
|
+
if (statSyncNoException(needle)) return needle;
|
90
|
+
}
|
91
|
+
|
92
|
+
d('Failed to find executable anywhere in path');
|
93
|
+
return exe;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Finds the actual executable and parameters to run on Windows. This method
|
98
|
+
* mimics the POSIX behavior of being able to run scripts as executables by
|
99
|
+
* replacing the passed-in executable with the script runner, for PowerShell,
|
100
|
+
* CMD, and node scripts.
|
101
|
+
*
|
102
|
+
* This method also does the work of running down PATH, which spawn on Windows
|
103
|
+
* also doesn't do, unlike on POSIX.
|
104
|
+
*
|
105
|
+
* @param {string} exe The executable to run
|
106
|
+
* @param {Array<string>} args The arguments to run
|
107
|
+
*
|
108
|
+
* @return {Object} The cmd and args to run
|
109
|
+
* @property {string} cmd The command to pass to spawn
|
110
|
+
* @property {Array<string>} args The arguments to pass to spawn
|
111
|
+
*/
|
112
|
+
function findActualExecutable(exe, args) {
|
113
|
+
// POSIX can just execute scripts directly, no need for silly goosery
|
114
|
+
if (process.platform !== 'win32') return { cmd: runDownPath(exe), args: args };
|
115
|
+
|
116
|
+
if (!_fs2.default.existsSync(exe)) {
|
117
|
+
// NB: When you write something like `surf-client ... -- surf-build` on Windows,
|
118
|
+
// a shell would normally convert that to surf-build.cmd, but since it's passed
|
119
|
+
// in as an argument, it doesn't happen
|
120
|
+
const possibleExts = ['.exe', '.bat', '.cmd', '.ps1'];
|
121
|
+
for (let ext of possibleExts) {
|
122
|
+
let possibleFullPath = runDownPath(`${ exe }${ ext }`);
|
123
|
+
|
124
|
+
if (_fs2.default.existsSync(possibleFullPath)) {
|
125
|
+
return findActualExecutable(possibleFullPath, args);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
if (exe.match(/\.ps1$/i)) {
|
131
|
+
let cmd = _path2.default.join(process.env.SYSTEMROOT, 'System32', 'WindowsPowerShell', 'v1.0', 'PowerShell.exe');
|
132
|
+
let psargs = ['-ExecutionPolicy', 'Unrestricted', '-NoLogo', '-NonInteractive', '-File', exe];
|
133
|
+
|
134
|
+
return { cmd: cmd, args: psargs.concat(args) };
|
135
|
+
}
|
136
|
+
|
137
|
+
if (exe.match(/\.(bat|cmd)$/i)) {
|
138
|
+
let cmd = _path2.default.join(process.env.SYSTEMROOT, 'System32', 'cmd.exe');
|
139
|
+
let cmdArgs = ['/C', `${ exe } ${ args.join(' ') }`];
|
140
|
+
|
141
|
+
return { cmd: cmd, args: cmdArgs };
|
142
|
+
}
|
143
|
+
|
144
|
+
if (exe.match(/\.(js)$/i)) {
|
145
|
+
let cmd = process.execPath;
|
146
|
+
let nodeArgs = [exe];
|
147
|
+
|
148
|
+
return { cmd: cmd, args: nodeArgs.concat(args) };
|
149
|
+
}
|
150
|
+
|
151
|
+
// Dunno lol
|
152
|
+
return { cmd: exe, args: args };
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Spawns a process but detached from the current process. The process is put
|
157
|
+
* into its own Process Group that can be killed by unsubscribing from the
|
158
|
+
* return Observable.
|
159
|
+
*
|
160
|
+
* @param {string} exe The executable to run
|
161
|
+
* @param {Array<string>} params The parameters to pass to the child
|
162
|
+
* @param {Object} opts Options to pass to spawn.
|
163
|
+
*
|
164
|
+
* @return {Observable<string>} Returns an Observable that when subscribed
|
165
|
+
* to, will create a detached process. The
|
166
|
+
* process output will be streamed to this
|
167
|
+
* Observable, and if unsubscribed from, the
|
168
|
+
* process will be terminated early. If the
|
169
|
+
* process terminates with a non-zero value,
|
170
|
+
* the Observable will terminate with onError.
|
171
|
+
*/
|
172
|
+
function spawnDetached(exe, params) {
|
173
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
174
|
+
|
175
|
+
var _findActualExecutable = findActualExecutable(exe, params);
|
176
|
+
|
177
|
+
let cmd = _findActualExecutable.cmd,
|
178
|
+
args = _findActualExecutable.args;
|
179
|
+
|
180
|
+
|
181
|
+
if (!isWindows) return spawn(cmd, args, Object.assign({}, opts || {}, { detached: true }));
|
182
|
+
const newParams = [cmd].concat(args);
|
183
|
+
|
184
|
+
let target = _path2.default.join(__dirname, '..', 'vendor', 'jobber', 'jobber.exe');
|
185
|
+
let options = Object.assign({}, opts || {}, { detached: true, jobber: true });
|
186
|
+
|
187
|
+
d(`spawnDetached: ${ target }, ${ newParams }`);
|
188
|
+
return spawn(target, newParams, options);
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Spawns a process attached as a child of the current process.
|
193
|
+
*
|
194
|
+
* @param {string} exe The executable to run
|
195
|
+
* @param {Array<string>} params The parameters to pass to the child
|
196
|
+
* @param {Object} opts Options to pass to spawn.
|
197
|
+
*
|
198
|
+
* @return {Observable<string>} Returns an Observable that when subscribed
|
199
|
+
* to, will create a child process. The
|
200
|
+
* process output will be streamed to this
|
201
|
+
* Observable, and if unsubscribed from, the
|
202
|
+
* process will be terminated early. If the
|
203
|
+
* process terminates with a non-zero value,
|
204
|
+
* the Observable will terminate with onError.
|
205
|
+
*/
|
206
|
+
function spawn(exe) {
|
207
|
+
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
208
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
209
|
+
|
210
|
+
opts = opts || {};
|
211
|
+
let spawnObs = _Observable.Observable.create(subj => {
|
212
|
+
let proc = null;
|
213
|
+
|
214
|
+
var _findActualExecutable2 = findActualExecutable(exe, params);
|
215
|
+
|
216
|
+
let cmd = _findActualExecutable2.cmd,
|
217
|
+
args = _findActualExecutable2.args;
|
218
|
+
|
219
|
+
d(`spawning process: ${ cmd } ${ args.join() }, ${ JSON.stringify(opts) }`);
|
220
|
+
let origOpts = Object.assign({}, opts);
|
221
|
+
if ('jobber' in origOpts) delete origOpts.jobber;
|
222
|
+
if ('split' in origOpts) delete origOpts.split;
|
223
|
+
|
224
|
+
proc = spawnOg(cmd, args, origOpts);
|
225
|
+
|
226
|
+
let bufHandler = source => b => {
|
227
|
+
if (b.length < 1) return;
|
228
|
+
let chunk = "<< String sent back was too long >>";
|
229
|
+
try {
|
230
|
+
chunk = b.toString();
|
231
|
+
} catch (e) {
|
232
|
+
chunk = `<< Lost chunk of process output for ${ exe } - length was ${ b.length }>>`;
|
233
|
+
}
|
234
|
+
|
235
|
+
subj.next({ source: source, text: chunk });
|
236
|
+
};
|
237
|
+
|
238
|
+
let ret = new _Subscription.Subscription();
|
239
|
+
|
240
|
+
if (opts.stdin) {
|
241
|
+
if (proc.stdin) {
|
242
|
+
ret.add(opts.stdin.subscribe(x => proc.stdin.write(x), subj.error, () => proc.stdin.end()));
|
243
|
+
} else {
|
244
|
+
subj.error(new Error(`opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required`));
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
let stderrCompleted = null;
|
249
|
+
let stdoutCompleted = null;
|
250
|
+
let noClose = false;
|
251
|
+
|
252
|
+
if (proc.stdout) {
|
253
|
+
stdoutCompleted = new _AsyncSubject.AsyncSubject();
|
254
|
+
proc.stdout.on('data', bufHandler('stdout'));
|
255
|
+
proc.stdout.on('close', () => {
|
256
|
+
stdoutCompleted.next(true);stdoutCompleted.complete();
|
257
|
+
});
|
258
|
+
} else {
|
259
|
+
stdoutCompleted = _Observable.Observable.of(true);
|
260
|
+
}
|
261
|
+
|
262
|
+
if (proc.stderr) {
|
263
|
+
stderrCompleted = new _AsyncSubject.AsyncSubject();
|
264
|
+
proc.stderr.on('data', bufHandler('stderr'));
|
265
|
+
proc.stderr.on('close', () => {
|
266
|
+
stderrCompleted.next(true);stderrCompleted.complete();
|
267
|
+
});
|
268
|
+
} else {
|
269
|
+
stderrCompleted = _Observable.Observable.of(true);
|
270
|
+
}
|
271
|
+
|
272
|
+
proc.on('error', e => {
|
273
|
+
noClose = true;
|
274
|
+
subj.error(e);
|
275
|
+
});
|
276
|
+
|
277
|
+
proc.on('close', code => {
|
278
|
+
noClose = true;
|
279
|
+
let pipesClosed = _Observable.Observable.merge(stdoutCompleted, stderrCompleted).reduce(acc => acc, true);
|
280
|
+
|
281
|
+
if (code === 0) {
|
282
|
+
pipesClosed.subscribe(() => subj.complete());
|
283
|
+
} else {
|
284
|
+
pipesClosed.subscribe(() => subj.error(new Error(`Failed with exit code: ${ code }`)));
|
285
|
+
}
|
286
|
+
});
|
287
|
+
|
288
|
+
ret.add(new _Subscription.Subscription(() => {
|
289
|
+
if (noClose) return;
|
290
|
+
|
291
|
+
d(`Killing process: ${ cmd } ${ args.join() }`);
|
292
|
+
if (opts.jobber) {
|
293
|
+
// NB: Connecting to Jobber's named pipe will kill it
|
294
|
+
_net2.default.connect(`\\\\.\\pipe\\jobber-${ proc.pid }`);
|
295
|
+
setTimeout(() => proc.kill(), 5 * 1000);
|
296
|
+
} else {
|
297
|
+
proc.kill();
|
298
|
+
}
|
299
|
+
}));
|
300
|
+
|
301
|
+
return ret;
|
302
|
+
});
|
303
|
+
|
304
|
+
return opts.split ? spawnObs : spawnObs.pluck('text');
|
305
|
+
}
|
306
|
+
|
307
|
+
function wrapObservableInPromise(obs) {
|
308
|
+
return new Promise((res, rej) => {
|
309
|
+
let out = '';
|
310
|
+
|
311
|
+
obs.subscribe(x => out += x, e => rej(new Error(`${ out }\n${ e.message }`)), () => res(out));
|
312
|
+
});
|
313
|
+
}
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Spawns a process but detached from the current process. The process is put
|
317
|
+
* into its own Process Group.
|
318
|
+
*
|
319
|
+
* @param {string} exe The executable to run
|
320
|
+
* @param {Array<string>} params The parameters to pass to the child
|
321
|
+
* @param {Object} opts Options to pass to spawn.
|
322
|
+
*
|
323
|
+
* @return {Promise<string>} Returns an Promise that represents a detached
|
324
|
+
* process. The value returned is the process
|
325
|
+
* output. If the process terminates with a
|
326
|
+
* non-zero value, the Promise will resolve with
|
327
|
+
* an Error.
|
328
|
+
*/
|
329
|
+
function spawnDetachedPromise(exe, params) {
|
330
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
331
|
+
|
332
|
+
return wrapObservableInPromise(spawnDetached(exe, params, opts));
|
333
|
+
}
|
334
|
+
|
335
|
+
/**
|
336
|
+
* Spawns a process as a child process.
|
337
|
+
*
|
338
|
+
* @param {string} exe The executable to run
|
339
|
+
* @param {Array<string>} params The parameters to pass to the child
|
340
|
+
* @param {Object} opts Options to pass to spawn.
|
341
|
+
*
|
342
|
+
* @return {Promise<string>} Returns an Promise that represents a child
|
343
|
+
* process. The value returned is the process
|
344
|
+
* output. If the process terminates with a
|
345
|
+
* non-zero value, the Promise will resolve with
|
346
|
+
* an Error.
|
347
|
+
*/
|
348
|
+
function spawnPromise(exe, params) {
|
349
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
350
|
+
|
351
|
+
return wrapObservableInPromise(spawn(exe, params, opts));
|
352
|
+
}
|
package/lib/src/index.d.ts
CHANGED
@@ -56,7 +56,7 @@ export declare function spawnDetached(exe: string, params: Array<string>, opts?:
|
|
56
56
|
* process terminates with a non-zero value,
|
57
57
|
* the Observable will terminate with onError.
|
58
58
|
*/
|
59
|
-
export declare function spawn<T>(exe: string, params?: Array<string>, opts?: any): Observable<T
|
59
|
+
export declare function spawn<T = string>(exe: string, params?: Array<string>, opts?: any): Observable<T>;
|
60
60
|
/**
|
61
61
|
* Spawns a process but detached from the current process. The process is put
|
62
62
|
* into its own Process Group.
|
package/lib/src/index.js
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
3
|
+
var t = {};
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
5
|
+
t[p] = s[p];
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
8
|
+
t[p[i]] = s[p[i]];
|
9
|
+
return t;
|
10
|
+
};
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
12
|
var path = require("path");
|
4
13
|
var net = require("net");
|
@@ -168,9 +177,10 @@ function spawn(exe, params, opts) {
|
|
168
177
|
if (opts === void 0) { opts = null; }
|
169
178
|
opts = opts || {};
|
170
179
|
var spawnObs = Observable_1.Observable.create(function (subj) {
|
180
|
+
var stdin = opts.stdin, optsWithoutStdIn = __rest(opts, ["stdin"]);
|
171
181
|
var _a = findActualExecutable(exe, params), cmd = _a.cmd, args = _a.args;
|
172
|
-
d("spawning process: " + cmd + " " + args.join() + ", " + JSON.stringify(
|
173
|
-
var origOpts = assign({},
|
182
|
+
d("spawning process: " + cmd + " " + args.join() + ", " + JSON.stringify(optsWithoutStdIn));
|
183
|
+
var origOpts = assign({}, optsWithoutStdIn);
|
174
184
|
if ('jobber' in origOpts) {
|
175
185
|
delete origOpts.jobber;
|
176
186
|
}
|
@@ -201,7 +211,7 @@ function spawn(exe, params, opts) {
|
|
201
211
|
var ret = new Subscription_1.Subscription();
|
202
212
|
if (opts.stdin) {
|
203
213
|
if (proc.stdin) {
|
204
|
-
ret.add(opts.stdin.subscribe(function (x) { return proc.stdin.write(x); }, subj.error, function () { return proc.stdin.end(); }));
|
214
|
+
ret.add(opts.stdin.subscribe(function (x) { return proc.stdin.write(x); }, subj.error.bind(subj), function () { return proc.stdin.end(); }));
|
205
215
|
}
|
206
216
|
else {
|
207
217
|
subj.error(new Error("opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required"));
|
package/lib/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2BAA6B;AAC7B,yBAA2B;AAC3B,wBAA0B;AAC1B,sCAAwC;AAExC,kCAAgC;AAChC,qCAAmC;AACnC,mCAAiC;AACjC,oCAAkC;AAClC,8CAA6C;AAE7C,kDAAiD;AACjD,kDAAiD;AAIjD,IAAM,OAAO,GAA8B,OAAO,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,qCAAqC;AAChH,IAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE/C,IAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,qCAAqC;AAE7E;;;;;;;GAOG;AACH,6BAA6B,IAAY;IACvC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,QA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of child_process.spawn",
|
5
5
|
"scripts": {
|
6
6
|
"doc": "echo \"esdoc may not work correctly\" && esdoc -c ./esdoc.json",
|
@@ -32,22 +32,22 @@
|
|
32
32
|
"rxjs": "^5.1.1"
|
33
33
|
},
|
34
34
|
"devDependencies": {
|
35
|
-
"@types/chai": "^
|
36
|
-
"@types/chai-as-promised": "
|
35
|
+
"@types/chai": "^4.0.4",
|
36
|
+
"@types/chai-as-promised": "^7.1.0",
|
37
37
|
"@types/mocha": "^2.2.39",
|
38
|
-
"@types/node": "^
|
38
|
+
"@types/node": "^8.0.32",
|
39
39
|
"babel-register": "^6.23.0",
|
40
|
-
"chai": "^
|
41
|
-
"chai-as-promised": "^
|
40
|
+
"chai": "^4.1.2",
|
41
|
+
"chai-as-promised": "^7.1.1",
|
42
42
|
"esdoc": "^0.5.2",
|
43
43
|
"esdoc-es7-plugin": "0.0.3",
|
44
44
|
"esdoc-plugin-async-to-sync": "^0.5.0",
|
45
45
|
"marked": "^0.3.6",
|
46
|
-
"mocha": "^
|
46
|
+
"mocha": "^4.0.0",
|
47
47
|
"npm-run-all": "^4.0.2",
|
48
|
-
"ts-node": "^
|
49
|
-
"tslint": "^
|
50
|
-
"typescript": "^2.
|
51
|
-
"uuid": "
|
48
|
+
"ts-node": "^3.3.0",
|
49
|
+
"tslint": "^5.7.0",
|
50
|
+
"typescript": "^2.5.3",
|
51
|
+
"uuid": "3.0.1"
|
52
52
|
}
|
53
53
|
}
|
package/src/index.ts
CHANGED
@@ -60,7 +60,7 @@ function runDownPath(exe: string): string {
|
|
60
60
|
return target;
|
61
61
|
}
|
62
62
|
|
63
|
-
let haystack = process.env.PATH
|
63
|
+
let haystack = process.env.PATH!.split(isWindows ? ';' : ':');
|
64
64
|
for (let p of haystack) {
|
65
65
|
let needle = path.join(p, exe);
|
66
66
|
if (statSyncNoException(needle)) {
|
@@ -112,14 +112,14 @@ export function findActualExecutable(exe: string, args: Array<string>): {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
if (exe.match(/\.ps1$/i)) {
|
115
|
-
let cmd = path.join(process.env.SYSTEMROOT
|
115
|
+
let cmd = path.join(process.env.SYSTEMROOT!, 'System32', 'WindowsPowerShell', 'v1.0', 'PowerShell.exe');
|
116
116
|
let psargs = ['-ExecutionPolicy', 'Unrestricted', '-NoLogo', '-NonInteractive', '-File', exe];
|
117
117
|
|
118
118
|
return { cmd: cmd, args: psargs.concat(args) };
|
119
119
|
}
|
120
120
|
|
121
121
|
if (exe.match(/\.(bat|cmd)$/i)) {
|
122
|
-
let cmd = path.join(process.env.SYSTEMROOT
|
122
|
+
let cmd = path.join(process.env.SYSTEMROOT!, 'System32', 'cmd.exe');
|
123
123
|
let cmdArgs = ['/C', exe, ...args];
|
124
124
|
|
125
125
|
return { cmd: cmd, args: cmdArgs };
|
@@ -185,15 +185,16 @@ export function spawnDetached(exe: string, params: Array<string>, opts: any = nu
|
|
185
185
|
* the Observable will terminate with onError.
|
186
186
|
*/
|
187
187
|
|
188
|
-
export function spawn<T>(exe: string, params: Array<string> = [], opts: any = null): Observable<T
|
188
|
+
export function spawn<T = string>(exe: string, params: Array<string> = [], opts: any = null): Observable<T> {
|
189
189
|
opts = opts || {};
|
190
190
|
let spawnObs = Observable.create((subj: Observer<{
|
191
191
|
source: any,
|
192
192
|
text: any
|
193
193
|
}>) => {
|
194
|
+
let { stdin, ...optsWithoutStdIn } = opts;
|
194
195
|
let { cmd, args } = findActualExecutable(exe, params);
|
195
|
-
d(`spawning process: ${cmd} ${args.join()}, ${JSON.stringify(
|
196
|
-
let origOpts = assign({},
|
196
|
+
d(`spawning process: ${cmd} ${args.join()}, ${JSON.stringify(optsWithoutStdIn)}`);
|
197
|
+
let origOpts = assign({}, optsWithoutStdIn);
|
197
198
|
if ('jobber' in origOpts) {
|
198
199
|
delete origOpts.jobber;
|
199
200
|
}
|
@@ -227,7 +228,7 @@ export function spawn<T>(exe: string, params: Array<string> = [], opts: any = nu
|
|
227
228
|
if (proc.stdin) {
|
228
229
|
ret.add(opts.stdin.subscribe(
|
229
230
|
(x: any) => proc.stdin.write(x),
|
230
|
-
subj.error,
|
231
|
+
subj.error.bind(subj),
|
231
232
|
() => proc.stdin.end()
|
232
233
|
));
|
233
234
|
} else {
|
@@ -294,7 +295,7 @@ export function spawn<T>(exe: string, params: Array<string> = [], opts: any = nu
|
|
294
295
|
}
|
295
296
|
|
296
297
|
function wrapObservableInPromise<T>(obs: Observable<T>) {
|
297
|
-
return new Promise((res, rej) => {
|
298
|
+
return new Promise<string>((res, rej) => {
|
298
299
|
let out = '';
|
299
300
|
|
300
301
|
obs.subscribe(
|