类: CommandLine
类: CommandLine
操作Chromium读取的应用程序的命令行参数
Process: Main
This class is not exported from the 'electron'
module. 它只能作为 Electron API 中其他方法的返回值。
下面的例子展示了如何检查—disable-gpu
标志是否设置。
const { app } = require('electron')
app.commandLine.hasSwitch('disable-gpu')
For more information on what kinds of flags and switches you can use, check out the Command Line Switches document.
实例方法
commandLine.appendSwitch(switch[, value])
switch
string - A command-line switch, without the leading--
.value
string (optional) - 给开关设置的值.
通过可选的参数 value
给 Chromium 中添加一个命令行开关。
** 注意: **该方法不会影响 process. argv
该功能是为控制Chromium行为设计的。
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
commandLine.appendArgument(value)
value
string - 要追加到命令行的参数.
在Chromium的命令行中附加一个参数。 参数会被正确引用。 无论附加顺序如何,切换将在参数之前进行。
如果你正在追加一个参数,如--switch=value
, 请考虑使用appendSwitch('switch', 'value')
const { app } = require('electron')
app.commandLine.appendArgument('--enable-experimental-web-platform-features')
** 注意: **该方法不会影响 process. argv
该功能是为控制Chromium行为设计的。
commandLine.hasSwitch(switch)
switch
string - 命令行开关.
返回boolean
- 命令行开关是否打开。
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
const hasPort = app.commandLine.hasSwitch('remote-debugging-port')
console.log(hasPort) // true
commandLine.getSwitchValue(switch)
switch
string - 命令行开关.
返回 string
- 命令行开关值。
This function is meant to obtain Chromium command line switches. It is not meant to be used for application-specific command line arguments. For the latter, please use process.argv
.
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
const portValue = app.commandLine.getSwitchValue('remote-debugging-port')
console.log(portValue) // '8315'
注意: 当开关不存在或没有值时,它返回空字符串。
commandLine.removeSwitch(switch)
switch
string - 命令行开关.
从Chromium命令行中移除指定的选项。
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
console.log(app.commandLine.hasSwitch('remote-debugging-port')) // true
app.commandLine.removeSwitch('remote-debugging-port')
console.log(app.commandLine.hasSwitch('remote-debugging-port')) // false
** 注意: **该方法不会影响 process. argv
该功能是为控制Chromium行为设计的。