subprocess.stdout


代表子进程的 stdoutReadable Stream

如果子进程衍生时 stdio[1] 设置为 'pipe' 以外的任何值,则此将是 null

subprocess.stdoutsubprocess.stdio[1] 的别名。 这两个属性将引用相同的值。

const { spawn } = require('node:child_process');

const subprocess = spawn('ls');

subprocess.stdout.on('data', (data) => {
  console.log(`Received chunk ${data}`);
});

如果子进程无法成功衍生,则 subprocess.stdout 属性可以是 nullundefined

A Readable Stream that represents the child process's stdout.

If the child was spawned with stdio[1] set to anything other than 'pipe', then this will be null.

subprocess.stdout is an alias for subprocess.stdio[1]. Both properties will refer to the same value.

const { spawn } = require('node:child_process');

const subprocess = spawn('ls');

subprocess.stdout.on('data', (data) => {
  console.log(`Received chunk ${data}`);
});

The subprocess.stdout property can be null or undefined if the child process could not be successfully spawned.