Skip to content

ChildProcess spawn ignores options param #24912

@eduardbme

Description

@eduardbme
  • Version: v9.10.1+
  • Platform: Darwin
  • Subsystem: child_process
const cp = require('child_process');

const pwd = cp.spawn('pwd', undefined, { cwd: '/' })

pwd.stdout.on('data', data => console.log(data.toString()));
admin$ pwd
/tmp
admin$ node test.js 
/tmp

I know how to fix it, just pass an empty array as a second argument, or completely skip it.

But that behavior a little bit weird, the second parameter (args) is optional, so I guessed undefined is okay for it.

When using TypeScript some IDEs suggests that undefined value could be passed (cuz param is optional) and that's why in my project I passed undefined to it and got a weird program behavior.

screen shot 2018-12-08 at 10 03 53 pm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions