| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c922578 commit 8169902
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1036,6 +1036,21 @@ child process, the `message` argument can contain data that JSON is not able | |||
| 1036 | 1036 | to represent. | |
| 1037 | 1037 | See [Advanced serialization][] for more details. | |
| 1038 | 1038 | ||
| 1039 | + ### Event: `'spawn'` | ||
| 1040 | + <!-- YAML | ||
| 1041 | + added: REPLACEME | ||
| 1042 | + --> | ||
| 1043 | + | ||
| 1044 | + The `'spawn'` event is emitted once the child process has spawned successfully. | ||
| 1045 | + | ||
| 1046 | + If emitted, the `'spawn'` event comes before all other events and before any | ||
| 1047 | + data is received via `stdout` or `stderr`. | ||
| 1048 | + | ||
| 1049 | + The `'spawn'` event will fire regardless of whether an error occurs **within** | ||
| 1050 | + the spawned process. For example, if `bash some-command` spawns successfully, | ||
| 1051 | + the `'spawn'` event will fire, though `bash` may fail to spawn `some-command`. | ||
| 1052 | + This caveat also applies when using `{ shell: true }`. | ||
| 1053 | + | ||
| 1039 | 1054 | ### `subprocess.channel` | |
| 1040 | 1055 | <!-- YAML | |
| 1041 | 1056 | added: v7.1.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -401,6 +401,8 @@ ChildProcess.prototype.spawn = function(options) { | |||
| 401 | 401 | this._handle.close(); | |
| 402 | 402 | this._handle = null; | |
| 403 | 403 | throw errnoException(err, 'spawn'); | |
| 404 | + } else { | ||
| 405 | + process.nextTick(onSpawnNT, this); | ||
| 404 | 406 | } | |
| 405 | 407 | ||
| 406 | 408 | this.pid = this._handle.pid; | |
@@ -466,6 +468,11 @@ function onErrorNT(self, err) { | |||
| 466 | 468 | } | |
| 467 | 469 | ||
| 468 | 470 | ||
| 471 | + function onSpawnNT(self) { | ||
| 472 | + self.emit('spawn'); | ||
| 473 | + } | ||
| 474 | + | ||
| 475 | + | ||
| 469 | 476 | ChildProcess.prototype.kill = function(sig) { | |
| 470 | 477 | ||
| 471 | 478 | const signal = sig === 0 ? sig : | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,8 @@ assert.strictEqual(enoentChild.stdio[0], enoentChild.stdin); | |||
| 41 | 41 | assert.strictEqual(enoentChild.stdio[1], enoentChild.stdout); | |
| 42 | 42 | assert.strictEqual(enoentChild.stdio[2], enoentChild.stderr); | |
| 43 | 43 | ||
| 44 | + enoentChild.on('spawn', common.mustNotCall()); | ||
| 45 | + | ||
| 44 | 46 | enoentChild.on('error', common.mustCall(function(err) { | |
| 45 | 47 | assert.strictEqual(err.code, 'ENOENT'); | |
| 46 | 48 | assert.strictEqual(getSystemErrorName(err.errno), 'ENOENT'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const spawn = require('child_process').spawn; | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const subprocess = spawn('echo', ['ok']); | ||
| 7 | + | ||
| 8 | + let didSpawn = false; | ||
| 9 | + subprocess.on('spawn', function() { | ||
| 10 | + didSpawn = true; | ||
| 11 | + }); | ||
| 12 | + function mustCallAfterSpawn() { | ||
| 13 | + return common.mustCall(function() { | ||
| 14 | + assert.ok(didSpawn); | ||
| 15 | + }); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + subprocess.on('error', common.mustNotCall()); | ||
| 19 | + subprocess.on('spawn', common.mustCall()); | ||
| 20 | + subprocess.stdout.on('data', mustCallAfterSpawn()); | ||
| 21 | + subprocess.stdout.on('end', mustCallAfterSpawn()); | ||
| 22 | + subprocess.stdout.on('close', mustCallAfterSpawn()); | ||
| 23 | + subprocess.stderr.on('data', common.mustNotCall()); | ||
| 24 | + subprocess.stderr.on('end', mustCallAfterSpawn()); | ||
| 25 | + subprocess.stderr.on('close', mustCallAfterSpawn()); | ||
| 26 | + subprocess.on('exit', mustCallAfterSpawn()); | ||
| 27 | + subprocess.on('close', mustCallAfterSpawn()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments