【问题标题】:Read Windows command line option in Electron renderer process在 Electron 渲染器进程中读取 Windows 命令行选项
【发布时间】:2017-12-16 12:06:57
【问题描述】:

我在 Windows 中部署了 Electron 应用程序。 我正在尝试在 .exe 上添加命令行选项。

“C:\Program Files\MyApp.exe”-调试

如何在我的应用程序中读取调试标志?我尝试使用 process.argv,但调试变量不存在。

【问题讨论】:

  • 您是否在远程渲染器进程中运行此程序?如果是这样,这就是您需要require('electron').remote 的原因。为了向未来的读者澄清,如果您可以将其添加到问题中(它在渲染器进程中),那就太棒了:)(我也可以更新我的答案)
  • 渲染器进程。你是对的,这取决于过程。更新您的答案,以便我将其标记为正确的答案。 :)
  • 太棒了!更新了两个答案以确保完整性

标签: windows process electron


【解决方案1】:

所有参数都在 process.argv 数组中。因此,如果您尝试从主进程访问参数,您可以使用以下命令:

//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"

如果您尝试从渲染器进程访问它们,则需要使用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"

【讨论】:

  • 不在那里。对不起。
  • 更新了渲染进程的案例
猜你喜欢
  • 2017-10-14
  • 2018-05-29
  • 2019-10-27
  • 2017-05-01
  • 2017-06-01
  • 2018-01-05
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
相关资源
最近更新 更多