subprocess.stdout
代表子进程的 stdout
的 Readable Stream
。
如果子进程衍生时 stdio[1]
设置为 'pipe'
以外的任何值,则此将是 null
。
subprocess.stdout
是 subprocess.stdio[1]
的别名。
这两个属性将引用相同的值。
const { spawn } = require('node:child_process');
const subprocess = spawn('ls');
subprocess.stdout.on('data', (data) => {
console.log(`Received chunk ${data}`);
});
如果无法成功衍生子进程,则 subprocess.stdout
属性可能是 null
。
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
if the child process could
not be successfully spawned.