你能帮忙看看下面这个用 grunt 运行的 node exec 命令的例子吗?
该echo
命令正在执行并hello-world.txt
已创建,但grunt.log.writeln
回调函数中的命令未触发。
var exec = require('child_process').exec,
child;
child = exec('echo hello, world! > hello-world.txt',
function(error, stdout, stderr){
grunt.log.writeln('stdout: ' + stdout);
grunt.log.writeln('stderr: ' + stderr);
if (error !== null) {
grunt.log.writeln('exec error: ' + error);
}
}
);
参考:
http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options