我有一个exe,我想从node.js中运行它,并传递一个参数,除了它不起作用外。.
var exec = require('child_process').execfile;
const fs = require('fs');
try {
if (fs.existsSync("./program/bin/Release/program.exe")) {
console.log("Exists")
} else {
console.log("Not Exists")
}
} catch(err) {
console.log(err)
}
setTimeout(function() {
exec('./program/bin/Release/program.exe manual',function(err,data) {
console.log(err)
console.log(data.toString());
});
},0);
它在打印时肯定存在,我可以从cmd提示符运行manual
作为参数来运行它。但是通过node.js,它不起作用。回来了
Error: spawn ./program/bin/Release/program.exe manual ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'ENOENT',code: 'ENOENT',syscall: 'spawn ./program/bin/Release/program.exe manual',path: './program/bin/Release/program.exe manual',spawnargs: [],cmd: './program/bin/Release/program.exe manual'
}
有人知道吗?
谢谢