Welcome to the Linux Foundation Forum!

execSync seems not output STDERR

Hi,
This is a question from Chapter 15. CREATING CHILD PROCESSES

Tutorial states that

The execSync method returns a buffer containing the output of the command. This is both STDOUT and STDERR output.

But run the following code and the output would be empty

'use strict'
const { execSync } = require('child_process')
const output = execSync(
    `node -e "console.error('subprocess stdio output')"`
)
console.log("The output is empty:", output.toString())

Comments

  • {
    output: Array[3] [null, Uint8Array[162], Uint8Array[0] ],
    pid: /pid/,
    signal: null,
    status: 1
    }

  • krave
    krave Posts: 26

    @robinson0001 said:
    {
    output: Array[3] [null, Uint8Array[162], Uint8Array[0] ],
    pid: /pid/,
    signal: null,
    status: 1
    }

    Hi, @robinson0001

    May I know your point based on your post?

  • @krave you're absolutely right, this is confirmed errata. What it should say is that only STDOUT is returned in the output buffer but STDERR is automatically sent to the parent (inherit) while STDOUT does not inherit when using execSync. This is being fixed, thanks for bringing it up.

Categories

Upcoming Training