如何在node.js上使用子进程运行top命令而不获得';超过标准输出最大缓冲区';从终点站
我试图创建一个RESTAPI,从VM获取度量,但是如果没有得到“超出标准输出maxBuffer”,我似乎无法运行我的子进程。这是我的密码如何在node.js上使用子进程运行top命令而不获得';超过标准输出最大缓冲区';从终点站,node.js,linux,Node.js,Linux,我试图创建一个RESTAPI,从VM获取度量,但是如果没有得到“超出标准输出maxBuffer”,我似乎无法运行我的子进程。这是我的密码 const { exec } = require('child_process'); exec('top', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); return; } co
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
获取一批信息,然后对其进行解析