在Electron渲染器过程中阅读Windows命令行选项 [英] Read Windows command line option in Electron renderer process

查看:88
本文介绍了在Electron渲染器过程中阅读Windows命令行选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆