使用node-windows nodeJs包运行带参数的脚本。

问题描述 投票:2回答:1

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

我如何用 node-windows?

这里的setup js脚本来自 计划 页面,将脚本值设置为'wiki start'会导致错误,因为模块将其视为文件。

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个回答
0
投票

这就是脚本的内容 脚本选项 参数的用途。它是以 [email protected]

var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\wiki.js',
  scriptOptions: 'start'
});
© www.soinside.com 2019 - 2024. All rights reserved.