Skip to content

Accessing process.stdin hangs on Windows #10836

Closed
@segrey

Description

Let's consider this example project consisting of 3 files:

// main.js
var spawn = require('child_process').spawn;
var middle = spawn(process.execPath, ['middle.js'], {
    'stdio': 'pipe'
});

middle.stdout.on('data', function(data) {
    process.stdout.write('stdout from middle: ' + data);
});

middle.stderr.on('data', function(data) {
    process.stdout.write('stderr from middle: ' + data);
});

middle.on('close', function(code) {
    process.stdout.write('middle process finished with exit code ' + code);
});
// middle.js
var spawn = require('child_process').spawn;
var stdin = process.stdin;
console.log('middle: isatty(stdin)=' +require('tty').isatty(stdin));
spawn(process.execPath, ['child.js'], {
    'stdio': [process.stdin, process.stdout, process.stderr]
});
// child.js
console.log('child: accessing process.stdin');
console.log('child: done successfully ' + process.stdin);

Running node main.js in cmd.exe should normally output these lines and exit

stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin
stdout from middle: child: done successfully [object Object]
middle process finished with exit code 0

However, from time to time it outputs only two first lines and hangs:

stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin

The hanging is caused by accessing process.stdin in child.js. Please note it works fine if process.stdin is replaced with 'pipe' here:

// middle.js
...
spawn(process.execPath, ['child.js'], {
    'stdio': ['pipe', process.stdout, process.stderr]
});

Node.js v7.4.0
OS Windows 10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions