在Electron渲染器过程中阅读Windows命令行选项 [英] Read Windows command line option in Electron renderer process
问题描述
我在Windows中已部署了Electron App。
我想在.exe上添加命令行选项。
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
"C:\Program Files\MyApp.exe" -debug
如何读取应用程序中的调试标志?我尝试使用process.argv,但调试变量不存在。
How I can read the debug flag inside my App? I tried with process.argv, but the debug variable isn't there.
推荐答案
您所有的参数都在<$ c内$ c> process.argv 数组。因此,如果您尝试从主流程访问参数,则可以使用以下命令:
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"
这篇关于在Electron渲染器过程中阅读Windows命令行选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!