subprocess.stdout


表示子进程的 stdout 的可读流。

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

subprocess.stdoutsubprocess.stdio[1] 的别名。 两个属性都将会指向相同的值。

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

const subprocess = spawn('ls');

subprocess.stdout.on('data', (data) => {
  console.log(`接收到数据块 ${data}`);
});

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('child_process');

const subprocess = spawn('ls');

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