![](/img/trans.png)
[英]exec error: Error: stdout maxBuffer exceeded if using child_process on Node js
[英]How do I run the top command with a child process on node.js without getting a 'stdout maxBuffer exceeded' from the terminal
我试图创建一个从虚拟机获取指标的REST API,但我似乎无法运行我的子进程而不会超出'stdout maxBuffer'。 这是我的代码
const { exec } = require('child_process');
exec('top', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
top
(使用它的默认参数)将继续写入stdout
- 它不只是转储一些信息并退出。
如果要使用top
,请查看手册页。 特别是-b
选项:
-b :Batch-mode operation
Starts top in 'Batch' mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set
with the '-n' command-line option or until killed.
所以尝试使用top -b -n 1
从top
获取单个“批量”信息,然后解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.