在nodejs中执行带参数的exe

Executing an exe with parameters in nodejs

我想用 node 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 中显示为:

file[ args][ options][ callback]

由于您没有提供任何选项,因此您应该像第一个示例一样传递一个数组。

execFile('oplrun', ['-de', 'output.dat', 'Test.mod','Test.dat'], function(err, data) {
        if(err) {
            console.log(err)
        } 
        else 
        console.log(data.toString());                       
    });