Skip to content

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

@AndrewPardoe

Description

@AndrewPardoe
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions