如何仅使用核心Node.js来检查文件系统状态。(作为'df'命令)



我想实现一个node.js程序来检查文件系统(如ext3..)的状态。但是,fs模块只提供文件的操作。我必须使用其他第三部分模块吗?

一个选项是捕获"df"命令的输出并对其进行解析

可以使用子进程运行命令。http://nodejs.org/docs/latest/api/child_processes.html#child_process.exec

var child_process = require('child_process');
child_process.exec('df', function(err, stdout, stderr) {
  // 'stdout' here is a string containing the things printed by 'df'
  console.log(stdout);
});

最新更新