私はnodejsでさまざまな子プロセスメソッドを試しています。私のコードでexecSyncが動作しないのはなぜですか?
var execSync = require('child_process').execSync;
function commandOutput(error, stdout, stderr) {
if (stderr !== null) {
console.error(stderr);
}
if (error !== null) {
console.error('execution error: ' + error);
}
if (stdout)console.log(stdout);
console.log("done");
}
var commandToExecute = "pwd";
execSync(commandToExecute, commandOutput);
console.log("executed");
execSyncは、次のエラーを与えると私は、すなわち幹部、上記のコード、とexecSyncを交換する場合、これは正常に動作している間:だからLinuxのコマンドを実行するために、私はそれが現在の作業ディレクトリを印刷し、このコードを、試してみました:
execSync(commandToExecute, commandOutput); ^ TypeError: undefined is not a function at Object. (/home/User_Name/fil.js:24:1) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3
どうしてですか?これが機能するにはどうすればよいですか?