Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node.js doesn't capture stdout or stderr from spawned process #1840

Closed
AndrewPardoe opened this issue Mar 31, 2017 · 2 comments
Closed

node.js doesn't capture stdout or stderr from spawned process #1840

AndrewPardoe opened this issue Mar 31, 2017 · 2 comments
Labels

Comments

@AndrewPardoe
Copy link

AndrewPardoe commented Mar 31, 2017

  • A brief description
    node.js running under WSL doesn't appear to capture stdout or stderr from a spawned Windows process. My test uses a small app that just prints to stdout and stderr. Running it under three configurations gives three results:
  1. spawning Linux app: stdout and stderr are captured in the node.js program (correct behavior)
  2. spawning Windows app from WSL file path: WSL error message about CWD is captured in stderr, no stdout is captured.
  3. spawning Windows app from Windows file path: no stderr, no stdout captured
  • Expected results
    node.js should capture the stdout and stderr from the child process

  • Actual results (with terminal output if applicable)
    no stdout and no stderr is captured

  • Your Windows build number
    16167.rs_lkg, Ubuntu 16.04.2 LTS

  • Steps / All commands required to reproduce the error from a brand new installation

  1. Create apps that output to stdout and stderr on both Windows path (in my code, c:\tmp) and WSL path (in my code, ~/tmp). I've called the apps hellostd.exe and hellostd.
#include <stdio.h>
int main() {
    fprintf(stderr, "hello stderr\n");
    fflush(stderr);   
    fprintf(stdout, "hello stdout\n");
    fflush(stdout);
    return 0;
}

node.js exectest.js. You have to uncomment each test--I'm not good enough at JavaScript to make this test handle all the cases. The output gets interleaved if they all run in one invocation.

const spawn = require('child_process').spawn;

// Running Linux app properly captures stderr & stdout
//const test = spawn('./hellostd');

// Running Windows app fills stderr with "Unable to translate CWD" error
//const test = spawn('/mnt/c/tmp/hellostd.exe');

// Changing directory into "Windows" leaves empty stderr & stdout
const test = spawn('/mnt/c/tmp/hellostd.exe', {
    cwd: "/mnt/c/tmp"
});


test.stdout.on('data', (data) => {
    console.log(`process stdout is: ${data}`);
});


test.stderr.on('data', (data) => {
    console.log(`process stderr is: ${data}`);
});

test.on('close', (code) => {
    console.log(`child process exited with code ${code}`);
});

This may be related to closed issue #1774 dealing with race conditions in node.js code running under WSL.

I'm internal to Microsoft, working on the MSVC team. Feel free to contact me directly.

@benhillis
Copy link
Member

Thanks for reporting this, I've dug into this and figured out the issue. It has to do with us reporting WSL socket file descriptors as "FILE_DEVICE_UNKNOWN" on NT which causes crt to not set up the stdout / stderr handles correctly. I'll get this fixed.

@benhillis
Copy link
Member

Look for this to be fixed soon after we begin flighting Windows vNext builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants