2021年1月19日星期二

NodeJS get output from child_process with command df -h on raspi

I'm using Raspberry Pi with nodeJS to do child_process.

On shell command, I do:

df -h  

and the output is:

Sistem Berkas  Besar   Isi  Sisa Isi% Dipasang di  /dev/root        58G  5,1G   50G  10% /  devtmpfs        460M     0  460M   0% /dev  tmpfs           464M  8,3M  456M   2% /dev/shm  tmpfs           464M   13M  452M   3% /run  tmpfs           5,0M  4,0K  5,0M   1% /run/lock  tmpfs           464M     0  464M   0% /sys/fs/cgroup  /dev/mmcblk0p1   44M   23M   22M  51% /boot  tmpfs            93M     0   93M   0% /run/user/1000  /dev/sda1       7,5G  2,0G  5,6G  27% /media/pi/USB DISK  

Then now I do on nodeJS script.

var exec = require('child_process').exec;    function execute(command, callback) {    var cmd = exec(command, function(error, stdout, stderr) {      console.log("error: " + error);      callback(stdout);    });  }    exec('df -h',(error,stdout,stderr) => {    if(error){      console.error( `exec error: ${error}` );      return;    }      var abc = [];    abc = stdout;      res.json(abc);  });  

My question, how can I get specific of the output? Example I just want to get at row 1, it's 50G

https://stackoverflow.com/questions/65802387/nodejs-get-output-from-child-process-with-command-df-h-on-raspi January 20, 2021 at 10:46AM

没有评论:

发表评论