Aji*_*ith 1 exe spawn execfile node.js
我想使用节点js执行exe。这是Windows命令提示符中命令的外观:
oplrun -D VersionId=3458 -de "output.dat" "Test.mod" "Test.dat"
Run Code Online (Sandbox Code Playgroud)
运行正常,我在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());
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我想将输出文件或版本作为参数传递,它将无法执行,并且也不会出现任何错误。这是代码:
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());
});
Run Code Online (Sandbox Code Playgroud)
如果需要传递-D VersionId = 1111或-de output.dat之类的参数,该如何传递参数。
谢谢阿吉斯
的签名execFile()在“ 节点”文档中显示为:
文件[,参数] [,选项] [,回调]
由于不提供任何选项,因此您应该像在第一个示例中那样传递单个数组。
execFile('oplrun', ['-de', 'output.dat', 'Test.mod','Test.dat'], function(err, data) {
if(err) {
console.log(err)
}
else
console.log(data.toString());
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6885 次 |
| 最近记录: |