[英]Executing an exe with parameters in nodejs
我想使用節點js執行exe。 這是Windows命令提示符中命令的外觀:
oplrun -D VersionId=3458 -de "output.dat" "Test.mod" "Test.dat"
運行正常,我在output.dat文件中得到了輸出。 現在,我想使用nodejs執行相同的操作,為此我使用了execFile。 如果我運行,它將運行正常:
var execFile = require('child_process').execFile;
execFile('oplrun',['Test.mod','Test.dat'], function(err, data) {
if(err) {
console.log(err)
}
else
console.log(data.toString());
});
但是,如果我想將輸出文件或版本作為參數傳遞,則它不會執行,並且也不會出現任何錯誤。 這是代碼:
var execFile = require('child_process').execFile;
var path ='D:\\IBM\\ILOG\SAMPLE\\output.dat';
execFile('oplrun', ['-de',path],['Test.mod','Test.dat'], function(err, data) {
if(err) {
console.log(err)
}
else
console.log(data.toString());
});
如果需要傳遞-D VersionId = 1111或-de output.dat之類的參數,該如何傳遞參數。
謝謝阿吉斯
execFile()
的簽名在Node docs中顯示為:
文件[,參數] [,選項] [,回調]
由於不提供任何選項,因此您應該像在第一個示例中那樣傳遞單個數組。
execFile('oplrun', ['-de', 'output.dat', 'Test.mod','Test.dat'], function(err, data) {
if(err) {
console.log(err)
}
else
console.log(data.toString());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.