Skip to content

shell option for execFile and execFileSync in child_process module not documented #18199

Closed

Description

@mojavelinux
  • Version: 8.9.4
  • Platform: n/a
  • Subsystem: child_process

The shell option for the execFile and execFileSync functions in the child_process module is not documented. However, it clearly works, as this mocha/chai test proves:

const { execFile, execFileSync } = require('child_process')
const expect = require('chai').expect

const EXEC_OPTS = { encoding: 'utf8', shell: process.env.SHELL }

describe('execFile()', () => {
  it('should run command using specified shell', async () => {
    let fn
    try {
      const result = await new Promise((resolve, reject) => {
        execFile('ls', ['*'], EXEC_OPTS, (err, stdout) =>
          err ? reject(err) : resolve(stdout))
      })
      fn = () => result
    } catch (err) {
      fn = () => { throw err }
    }
    expect(fn).to.not.throw()
  })
})

describe('execFileSync()', () => {
  it('should run command using specified shell', () => {
    expect(() => execFileSync('ls', ['*'], EXEC_OPTS)).to.not.throw()
  })
})

I'm happy to add documentation for this option. I just need to know if this behavior is intention or whether it's the result of leaky internals.

Activity

  1. added
    child_process
    doc
    on Jan 17, 2018
  2. bnoordhuis commented on Jan 17, 2018

    @bnoordhuis
    Member

    I suppose it's undocumented because of this paragraph:

    The child_process.execFile() function is similar to child_process.exec() except that it does not spawn a shell. Rather, the specified executable file is spawned directly as a new process making it slightly more efficient than child_process.exec().

  3. mojavelinux commented on Jan 18, 2018

    @mojavelinux
    Author

    I get that's the default behavior. But this function is still useful for executing in a shell because it accepts arguments as an array instead of a string as exec does. Depending on the circumstances, that can prove to be useful if the arguments are already prepared.

  4. added
    good first issue
    on Jan 18, 2018
  5. jvelezpo commented on Jan 18, 2018

    @jvelezpo
    Contributor

    I can work on it, and it will be my first issue and my first contribution to the core 😎

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

    child_processdocgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions