0
我使用exec命令來通過安裝child_process節點模塊來理解它。下面是代碼行。 通過查看輸出,它顯示我的exec()
未按預期工作。exec()命令沒有在標準輸出中顯示輸出
exec.js
console.log('1')
var exec = require('child_process').exec;
console.log('2');
exec('node -v', function (error, stdout, stderr) {
console.log('stdout', +stdout);
console.log('stderr', +stderr);
if (error !== null) {
console.log('exec error: ', + error);
}
});
的package.json
{
"name": "exec",
"version": "1.0.0",
"description": "",
"main": "exec.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"child_process": "^1.0.2"
}
}
當運行命令node exec.js
它顯示以下輸出如下
1
2
stdout NaN
stderr 0