Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在node.js上使用子进程运行top命令而不获得';超过标准输出最大缓冲区';从终点站_Node.js_Linux - Fatal编程技术网

如何在node.js上使用子进程运行top命令而不获得';超过标准输出最大缓冲区';从终点站

如何在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

我试图创建一个RESTAPI,从VM获取度量,但是如果没有得到“超出标准输出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
获取一批信息,然后对其进行解析