Function execa

  • Execute a file.

    Think of this as a mix of child_process.execFile and child_process.spawn.

    Parameters

    • file: string

      The program/script to execute.

    • Optionalarguments: readonly string[]

      Arguments to pass to file on execution.

    • Optionaloptions: Options<string>

    Returns ExecaChildProcess<string>

    A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.

    import execa = require('execa');

    (async () => {
    const {stdout} = await execa('echo', ['unicorns']);
    console.log(stdout);
    //=> 'unicorns'

    // Cancelling a spawned process
    const subprocess = execa('node');
    setTimeout(() => { spawned.cancel() }, 1000);
    try {
    await subprocess;
    } catch (error) {
    console.log(subprocess.killed); // true
    console.log(error.isCanceled); // true
    }
    })();

    // Pipe the child process stdout to the current stdout
    execa('echo', ['unicorns']).stdout.pipe(process.stdout);
  • Parameters

    • file: string
    • Optionalarguments: readonly string[]
    • Optionaloptions: Options<null>

    Returns ExecaChildProcess<Buffer>

  • Parameters

    • file: string
    • Optionaloptions: Options<string>

    Returns ExecaChildProcess<string>

  • Parameters

    • file: string
    • Optionaloptions: Options<null>

    Returns ExecaChildProcess<Buffer>