【问题标题】:Running a script with parameters with node-windows nodeJs package使用 node-windows nodeJs 包运行带有参数的脚本
【发布时间】:2018-10-23 16:15:21
【问题描述】:

我想作为服务运行的脚本需要 'start' 作为参数。

如何使用node-windows设置参数?

这里是来自project 页面的设置 js 脚本:

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\wiki.js',
  nodeOptions: [
    '--harmony',
    '--max_old_space_size=4096'
  ]
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

将脚本值设置为“wiki start”会导致错误,因为模块将其视为文件。 这里是日志:

Starting C:\Program Files\nodejs\node.exe  --harmony --max_old_space_size=4096 C:\Users\<me>\AppData\Roaming\npm\node_modules\node-windows\lib\wrapper.js --file ..\wiki.js --log "wiki.js wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined "-- start"

我也尝试发送nodeOptions,将“--start”添加到数组中,但模块将其作为字符串添加到命令行,即“--start”。

【问题讨论】:

    标签: node.js windows-services node-windows


    【解决方案1】:

    这就是scriptOptions 参数的用途。它是用node-windows@0.1.11介绍的

    var svc = new Service({
      name:'Hello World',
      description: 'The nodejs.org example web server.',
      script: 'C:\\path\\to\\wiki.js',
      scriptOptions: 'start'
    });
    

    【讨论】:

      猜你喜欢
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多