node子进程(Child Process)获取硬盘分区
node child_process文档
child_process.exec(command[, options][, callback])
- command<string> The command to run, with space-separated arguments.
- options<Object>- cwd<string> Current working directory of the child process. Default:- null.
- env<Object> Environment key-value pairs. Default:- null.
- encoding<string> Default:- 'utf8'
- shell<string> Shell to execute the command with. See Shell Requirements and Default Windows Shell. Default:- '/bin/sh'on UNIX,- process.env.ComSpecon Windows.
- timeout<number> Default:- 0
- maxBuffer<number> Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at- maxBufferand Unicode. Default:- 200 * 1024.
- killSignal<string> | <integer> Default:- 'SIGTERM'
- uid<number> Sets the user identity of the process (see- setuid(2)).
- gid<number> Sets the group identity of the process (see- setgid(2)).
- windowsHide<boolean> Hide the subprocess console window that would normally be created on Windows systems. Default:- false.
 
- callback<Function> called with the output when process terminates.
 
init(list){//得到硬盘分区的数组
            let ths = this;
            let lists = ths.arrayTrim(list);
            return lists;    
}
arrayTrim(arr){//数组中各元素的空格去除
            arr.shift();
            arr.forEach(function(item, index){
                arr[index] = item.trim();
            });
            return arr;
}
logicaldisk(){//获取自盘分区的字符串
            var ths = this;
            spawn.exec('wmic logicaldisk get caption', {
                windowsHide: true
            }, function(err, stdout, stderr) {
                if(err || stderr) { 
                    console.log("root path open failed" + err + stderr);
                    return;
                }
                let disks = stdout.trim().split('\n');
                ths.init(disks);
            })
}
本文来自博客园,作者:_zhiqiu,转载请注明原文链接:https://www.cnblogs.com/guojikun/p/9120562.html

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号