list partitions in nodejs

前端 未结 4 1274
说谎
说谎 2020-12-30 11:20

I would like to get the list of partitions in windows, using nodejs. fs.readdir works fine for any folder below or including C:, but I cant figure out what to give it to hav

4条回答
  •  天命终不由人
    2020-12-30 11:42

    There is no api in node.js to list partitions. One workaround is to use child_process and execute wmic command (or any command which can list partitions).

    var spawn = require('child_process').spawn,
        list  = spawn('cmd');
    
    list.stdout.on('data', function (data) {
      console.log('stdout: ' + data);
    });
    
    list.stderr.on('data', function (data) {
      console.log('stderr: ' + data);
    });
    
    list.on('exit', function (code) {
      console.log('child process exited with code ' + code);
    });
    
    list.stdin.write('wmic logicaldisk get name\n');
    list.stdin.end();
    

提交回复
热议问题