【发布时间】:2016-10-06 11:45:57
【问题描述】:
说如果这是linux shell,我想做的是:
copy file1 tmp
rename tmp file2
我可以做瀑布
function copyFile(cb) {
child_process.exec('cp file1 tmp', function (error, stdout, stderr) {
......
});
}
async.waterfall([
copyFile,
renameFile
], function (error) {
if (error) {
//handle readFile error or processFile error here
}
});
或者猜猜我能做到
child_process.execSync('cp file1 tmp");
child_process.execSync('rename tmp file2');
请问有什么区别?例如性能?阻塞? 非常感谢!
【问题讨论】:
-
结果和你已经知道的一样,但是 1. version 是异步 IO 风格,最适合 Node.js,从性能角度来看应该更好,但是 2. version 更具可读性@ 987654321@
-
对于版本 1,它会创建一个单独的进程吗?
-
没错,child_process.exec 总是在创建进程。
-
实际上我的问题是:瀑布也创建子进程?我猜是这样的。
-
否
async.waterfall不会自己创建进程,但是如果你在里面使用child_process.exec,它会在执行过程中创建进程。
标签: node.js