Skip to content

child_process never stops - powershell - windows 7 #25645

@koraniar

Description

@koraniar

Node: v10.15.0
Windows: 7 Version 6.1 Build 7601

When Exec, ExecFile or Spawn is executed calling powershell.exe the console never ends until timeout

Example Code

const fs = require('fs');
const cp = require('child_process');
const exec = cp.exec;
const spawn = cp.spawn;
const execFile = cp.execFile;

function execTest() {
  exec('powershell.exe hostname', { timeout: 300000 }, (error, stdout, stderr) => {
    if (error) {
      console.error(`exec error: ${error}`);
      return;
    }
    console.log(`exec stdout: ${stdout}`);
    console.log(`exec stderr: ${stderr}`);
  });
}

function execFileTest() {
  execFile('powershell.exe', ['hostname'], { timeout: 300000 }, (error, stdout, stderr) => {
    if (error) {
      console.error(`execFile error: ${error}`);
      return;
    }
    console.log(`execFile stdout: ${stdout}`);
    console.log(`execFile stderr: ${stderr}`);
  });
}

function spawnTest() {
  const ls = spawn('powershell.exe', ['hostname'], { timeout: 300000 });

  ls.stdout.on('data', (data) => {
    console.log(`spawn stdout: ${data}`);
  });

  ls.stderr.on('data', (data) => {
    console.log(`spawn stderr: ${data}`);
  });

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

execTest();
execFileTest();
spawnTest();

Console Output

spawn stdout: root-PC
(after 5 minutes)
exec error: Error: Command failed: powershell.exe hostname

execFile error: Error: Command failed: powershell.exe hostname
(spawn never ends)

On windows 8 and 10 all examples are working well.

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.wontfixIssues that will not be fixed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions