使用 Node.js 调用child_process与从 C 调用子进程并创建C++绑定以从 node.js 调用
Calling child_process with Node.js vs calling child process from C and creating a C++ bind to call from node.js
我想调用pdftotext来提取100.000个文件的内容(我需要快(,那么,这两种实现中哪一种是最快的?
实施 1:
从 node.js 为每个提取创建一个child_process:
export default (file) => new Promise((resove, reject) => {
const command = 'pdftotext'
const args = ['-layout', '-enc', 'UTF-8', file, '-']
const process = spawn(command, args)
const stdout = []
const stderr = []
process.stdout.on('data', (data) => {
stdout.push(data)
})
process.stderr.on('data', (data) => {
stderr.push(data)
})
process.on('error', (error) => {
if (error.code === 'ENOENT')
error.message = 'pdftotext is not installed, so will be unable to extract the file content'
reject(error)
})
process.on('close', () => {
if (stderr.length)
return reject(stderr.map(Error))
resolve(stdout.join())
})
}
实施 2:
从 C 创建child_process,并创建要从节点调用的C++绑定.js
--没有代码,因为我还在学习如何做 --
最有可能的是,进程调用代码会对性能产生不必要的影响,文档处理的速度取决于pdftotext实现和磁盘io。所以我想没有必要费心编写自定义进程启动器。
相关文章:
- 使用 Node.js N-API 调用 C 函数时,不会显示预期的输出
- node.js Nan:在函数C++调用 JavaScript 回调
- 如果用户尝试从 JS 调用对象的未定义函数C++则回调C++代码
- 从 JS (V8) 中C++对象的引用调用函数
- 如何使用 cocos creator 在 Cocos2d-X/Cocos2d-JS 中调用 javascript 函数并
- 使用 Node.js 调用child_process与从 C 调用子进程并创建C++绑定以从 node.js 调用
- 从不同的节点插件方法多次调用JS函数
- 从节点addon多次调用JS函数
- 从嵌入式 v8 调用 webassembly 而不带 JS
- 从C 插件中调用QML中的JS函数
- 如何从 firefox-addon / js-ctypes 调用C++类实例
- JavaScript:从浏览器和 Node.js 中的 JavaScript 代码调用C++库
- 如何从node.js调用外部脚本/程序
- 节点.JS,C++模块:为什么当我尝试调用本地的长度方法时出现段错误<Array>?
- 如何从Node.js调用C++代码
- 在使用NAN的Node.js的C++模块中未调用SetAccessor函数
- 使用Node.js中包含char数组的结构调用C++dll
- 使用node.js从C++调用JavaScript
- 是否可以使用eclipseCDT代替vc++,以便使用SWIG调用node.js中的C++库
- 通过事件发射调用JS函数