node-webkit如何parsing“open”事件参数?

我需要一个包含所有参数的数组,如gui.App.argv中的值
是否有一些函数来parsing这个?

function openfile(cmdline){ console.log('command line: ' + cmdline); } openfile(gui.App.argv); //my file.txt, my file.txt (this is what I need) gui.App.on('open', function(cmdline) { openfile(cmdline); //app.exe --original-process-start-time=13049249391168190 "my file.txt" "my file2.txt" }); 

我刚刚遇到同样的问题,这是我如何解决它:

 // Listen to `open` event gui.App.on('open', function (cmdline) { // Break out the params from the command line var arr = /(.*)--original-process-start-time\=(\d+)(.*)/.exec(cmdline); // Get the last match and split on spaces var params = arr.pop().split(' '); console.log('Array of parameters', params); }); 

这只要不改变事件的输出结构(即–original-process-start-time标志),但是如果和当他们这样做,我会考虑使用process.execPath

我的解决scheme
1.用“ ”之类的思维replace引号中的所有空格 (HTML空间)。
2.用空格分隔string。
3.将“ ”replace 由空间。

 gui.App.on('open', function(cmdline) { cmdline = cmdline.replace(/"([^"]+)"/g, function(a) { return a.replace(/\s/g, "&nbsp;"); }).split(' '); for (var i = 0, length = cmdline.length, arg = '', args = []; i < length; ++i) { arg = cmdline[i].replace(/&nbsp;/g, ' '); // Filter by exe file and exe args. if (arg === '"' + process.execPath + '"' || arg.search(/^\-\-/) === 0) continue; args.push(arg); } console.log(args); }); 

在0.14.x,0.15.x上工作。