小编Aji*_*ith的帖子

使用Node.js中的参数执行exe

我想使用节点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之类的参数,该如何传递参数。

谢谢阿吉斯

exe spawn execfile node.js

1
推荐指数
1
解决办法
6885
查看次数

标签 统计

exe ×1

execfile ×1

node.js ×1

spawn ×1