I have a deployed Electron App in Windows. I'm trying to add a command line option on the .exe.
"C:\Program Files\MyApp.exe" -debug
How I can read the debug flag inside my App? I tried with process.argv, but the debug variable isn't there.
All your arguments are inside the process.argv
array. So if you are trying to access the arguments from the main process you can just use the following:
//the command you called is always argv[0]
process.argv[0] == "C:\Program Files\MyApp.exe"
//every other argument, separated by spaces, is in the array in order
process.argv[1] == "-debug"
If you are trying to access them from a renderer process however, you need to use electron remote.
const remote = require('electron').remote
//the command you called is always argv[0]
remote.process.argv[0] == "C:\Program Files\MyApp.exe"
//every other argument, separated by spaces, is in the array in order
remote.process.argv[1] == "-debug"
来源:https://stackoverflow.com/questions/45051296/read-windows-command-line-option-in-electron-renderer-process