类: 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])
switchstring - A command-line switch, without the leading--.valuestring (optional) - 给开关设置的值.
通过可选的参数 value 给 Chromium 中添加一个命令行开关。
[!NOTE] This will not affect
process.argv. The intended usage of this function is to control Chromium's behavior.
const{ app }=require('electron')
app.commandLine.appendSwitch('remote-debugging-port','8315')
commandLine.appendArgument(value)
valuestring - 要追加到命令行的参数.
在Chromium的命令行中附加一个参数。 参数会被正确引用。 无论附加顺序如何,切换将在参数之前进行。
如果你正在追加一个参数,如--switch=value, 请考虑使用appendSwitch('switch', 'value')
const{ app }=require('electron')
app.commandLine.appendArgument('--enable-experimental-web-platform-features')
[!NOTE] This will not affect
process.argv. The intended usage of this function is to control Chromium's behavior.
commandLine.hasSwitch(switch)
switchstring - 命令行开关.
返回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)
switchstring - 命令行开关.
返回 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'
[!NOTE] When the switch is not present or has no value, it returns empty string.
commandLine.removeSwitch(switch)
switchstring - 命令行开关.
从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
[!NOTE] This will not affect
process.argv. The intended usage of this function is to control Chromium's behavior.