Skip to content

child_process - windowsHide not working with detached: true #21825

Closed

Description

@affanshahid
  • Version: v10.6.0
  • Platform: Windows 10 64-bit
  • Subsystem: child_process

Running the following results in a command prompt popping up to run the command, and the output not being piped correctly.

const log = fs.openSync('./log.out', 'w');

const c = cp.spawn(
  'npm.cmd', 
  ['-g', 'ls', '--depth', '0'],
  {stdio: ['ignore', log, log], detached: true, shell: false, windowsHide: true}
);

Removing detached makes everything work just fine. But the command wont run if the parent dies, which is something I don't want in the actual scenario.

Activity

  1. bzoz commented on Jul 18, 2018

    @bzoz
    Contributor

    It looks like it is because npm.cmd is a shell script. So it gets a shell with a window. This code, which runs npm js file directly:

    const log = require('fs').openSync('./log.out', 'w');
    
    const c = require('child_process').spawn(
      'node.exe', 
      ['C:\\...\\node_modules\\npm\\bin\\npm-cli.js', '-g', 'ls', '--depth', '0'],
      {stdio: ['ignore', log, log], detached: true, shell: false, windowsHide: true}
    );

    acts as expected, no window is spawned.

  2. corneliuc commented on Jul 19, 2018

    @corneliuc

    Hello,

    I have the same problem.
    In the below example, I want to respawn a node process with detached = true which will spawn another process of procdump. In this case, the window is popping out and I don't want this happening.
    I've put windowsHide flag on true but is not working.

    Could you please help me?

    Example:
    ==nodeSpawn.js file
    let child_process = require("child_process");
    const nodePath = "C:\Program Files\nodejs\node.exe";
    child_process.spawn(nodePath,['procDumpSpawn.js'],{
    detached: true, //=>is working without detached true
    stdio: 'ignore',
    shell: false,
    windowsHide: true
    });

    ==procDumpSpawn.js file
    let child_process = require("child_process");
    const procDumpPath = "C:\procdump.exe";
    child_process.spawn(procDumpPath, ['notepad'],{
    stdio: 'ignore',
    });
    Run: node nodeSpawn.js

    Corneliu,

  3. ledmirage commented on Dec 28, 2018

    @ledmirage

    same thing here on node v10.14.2
    i am using spawn to launch external exe (rethinkdb) with detached = true, and console window is popping up even windowsHide is set to true.
    is there any workaround for this?

  4. added
    windowsIssues and PRs related to the Windows platform.
    on Dec 29, 2018
  5. ryzokuken commented on Dec 29, 2018

    @ryzokuken
    Contributor

    /cc @nodejs/platform-windows @bzoz is this expected behavior?

  6. seishun commented on Dec 29, 2018

    @seishun
    Contributor

    Seems to be the expected behavior per @bzoz's comment.

  7. ledmirage commented on Dec 29, 2018

    @ledmirage

    per bzoz's comment, the original issue seems to be due to spawning a script, but if spawning an exe it shall be okay, but for my case i was indeed spawning an exe as well.
    just as side note, if i use execFile there was no pop up, but i need to use spawn in order to have detacted option (because i want to prevent SIGINT from passing down to child process)

  8. bzoz commented on Jan 2, 2019

    @bzoz
    Contributor

    @ledmirage use shell: false option

  9. ledmirage commented on Jan 3, 2019

    @ledmirage

    @bzoz tried that as well, but the pop up is still there
    i am testing on Windows 10.

    this is the code snippet:
    const subprocess = child_process.spawn(cmd, args, {
    detached: true
    , stdio: 'ignore'
    , shell: false
    });

  10. bzoz commented on Jan 3, 2019

    @bzoz
    Contributor

    @ledmirage: what is your exact Node version and what exactly are you trying to run?

  11. ledmirage commented on Jan 6, 2019

    @ledmirage
  12. bzoz commented on Jan 7, 2019

    @bzoz
    Contributor

    Looks like this rethinkdb just needs some console for output. If you set stdio option to inherit or pipe the window will not appear.

    Anyway, all this should be documented and added to windowHide option description.

  13. ledmirage commented on Jan 8, 2019

    @ledmirage

    @bzoz tried both inherit and pipe and together with windowsHide = true, still no luck
    i will probably just accept this for now if no workaround

  14. bzoz commented on Jan 8, 2019

    @bzoz
    Contributor

    @ledmirage sorry to hear that. It worked for me though, maybe there is something in your app that affects this?

    Could you verify that a simple script with only the spawn command still exibits this behavior?

  15. 22 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.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