简体   繁体   中英

Electron second instance's command line arguments are corrupted?

I am following the example for requestSingleInstanceLock() in the Electron's documentation. For some reason the second instance's command line arguments seem corrupted if the arguments have quoted values with spaces inside. The initial process.argv looks just fine, however the argv parameter in the second-instance event comes split at the spaces adding additional argument values, all values are transformed to lower case, and somewhat presorted.

Is there a way to disable this processing, and eventually pass/get the command line of the second instance as is?

NOTE: I have used app.makeSingleInstance() in previous Electron versions, however this API has been removed.

Here's an excerpt from the test app I use:

console.log(process.argv);

if (!app.requestSingleInstanceLock()) {
  app.exit();
}

app.on('second-instance', (event, argv, workingDirectory) => {
  console.log('second-instance', argv);
});

Here's the result:

C:\electron-app-win32-x64>electron-app.exe "/Arg1 Value1" "/Arg2 Value2"

C:\electron-app-win32-x64>
[
  'C:\\electron-app-win32-x64\\electron-app.exe',
  '/Arg1 Value1',
  '/Arg2 Value2'
]
second-instance [   <--- from the same command in another console
  'electron-app.exe',
  '/arg1',
  '/arg2',
  '--allow-file-access-from-files',
  '--original-process-start-time=13232862957593703',
  'value1',
  'value2'
]

It's

Chromium's command-line parsing logic. Chromium treats "switches" (things like --foo or --foo=bar) and "arguments" (things that don't begin with --) separately

You can find links to Chromium source and some hacks to get around this logic in this github issue. https://github.com/electron/electron/issues/20322

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM