subprocess.stdout


Readable Stream 表示子进程的 stdout

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

如果子进程的 stdio[1] 被设置为除 'pipe' 之外的任何值,那么它将为 null

【If the child process was spawned with stdio[1] set to anything other than 'pipe', then this will be 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}`);
});import { spawn } from 'node:child_process';

const subprocess = spawn('ls');

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

subprocess.stdout 属性可能为 nullundefined,如果子进程未能成功启动。

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