node子进程(Child Process)获取硬盘分区

简介: 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.ComSpec on 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 maxBuffer and 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.
• error <Error>
• stdout <string> | <Buffer>
• stderr <string> | <Buffer>
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);
            })
}

相关文章
|
9月前
|
前端开发
bat 批处理文件 结束node进程 杀死指定端口
bat 批处理文件 结束node进程 杀死指定端口
|
1月前
|
负载均衡 JavaScript 算法
Node.js 多进程的概念、原理、优势以及如何使用多进程来提高应用程序的性能和可伸缩性
Node.js 多进程的概念、原理、优势以及如何使用多进程来提高应用程序的性能和可伸缩性
77 1
|
1天前
|
运维 JavaScript Devops
阿里云云效操作报错合集之node.js构建时,报错:The build failed because the process exited too early.该怎么办
本合集将整理呈现用户在使用过程中遇到的报错及其对应的解决办法,包括但不限于账户权限设置错误、项目配置不正确、代码提交冲突、构建任务执行失败、测试环境异常、需求流转阻塞等问题。阿里云云效是一站式企业级研发协同和DevOps平台,为企业提供从需求规划、开发、测试、发布到运维、运营的全流程端到端服务和工具支撑,致力于提升企业的研发效能和创新能力。
|
2天前
|
JavaScript 前端开发 Shell
深入Node.js的进程与子进程:从文档到实践
深入Node.js的进程与子进程:从文档到实践
|
10天前
|
缓存 JavaScript Unix
Node.js 多进程
Node.js 多进程
13 0
|
1月前
|
JavaScript Unix API
Nodejs 第十四章(process)
Nodejs 第十四章(process)
38 0
|
1月前
|
消息中间件 监控 JavaScript
Node.js中的进程管理:child_process模块与进程管理
【4月更文挑战第30天】Node.js的`child_process`模块用于创建子进程,支持执行系统命令、运行脚本和进程间通信。主要方法包括:`exec`(执行命令,适合简单任务)、`execFile`(安全执行文件)、`spawn`(实时通信,处理大量数据)和`fork`(创建Node.js子进程,支持IPC)。有效的进程管理策略涉及限制并发进程、处理错误和退出事件、使用流通信、谨慎使用IPC以及监控和日志记录,以确保应用的稳定性和性能。
|
11月前
|
JSON 资源调度 负载均衡
这可能是你见过最全的Node.js应用程序管理与部署:使用PM2进行进程管理
node是单线程应用,单线程最大的弊端就是无法利用多核CPU带来的优势来提升运行效率。 pm2(process manager)是一个进程管理工具,可以用它来管理node进程,负责所有的node进程,并查看node进程的状态,也支持性能监控,负载均衡等功能。
314 0
这可能是你见过最全的Node.js应用程序管理与部署:使用PM2进行进程管理
|
11月前
|
JavaScript
使用 Node.js 多进程提高任务执行效率
使用 Node.js 多进程提高任务执行效率
103 0
|
2天前
|
监控 Linux 应用服务中间件
探索Linux中的`ps`命令:进程监控与分析的利器
探索Linux中的`ps`命令:进程监控与分析的利器