Skip to content

Accessing process.stdin hangs on Windows #10836

Description

@segrey

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

// main.jsvarspawn=require('child_process').spawn;varmiddle=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.jsvarspawn=require('child_process').spawn;varstdin=process.stdin;console.log('middle: isatty(stdin)='+require('tty').isatty(stdin));spawn(process.execPath,['child.js'],{'stdio': [process.stdin,process.stdout,process.stderr]});
// child.jsconsole.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

Metadata

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