Skip to main content

Class: CommandLine

Class: CommandLine

Manipulate the command line arguments for your app that Chromium reads操作Chromium读取的应用程序的命令行参数

Process:进程:Main
This class is not exported from the 'electron' module. 此类不是从'electron'模块导出的。It is only available as a return value of other methods in the Electron API.它只能作为Electron API中其他方法的返回值。

The following example shows how to check if the --disable-gpu flag is set.以下示例显示了如何检查--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.有关可以使用哪种标志和开关的详细信息,请查看命令行开关文档。

Instance Methods实例方法

commandLine.appendSwitch(switch[, value])

  • switch string - A command-line switch, without the leading --命令行开关,不带前导--
  • value string (optional) - A value for the given switch给定开关的值

Append a switch (with optional value) to Chromium's command line.将一个开关(具有可选value)附加到Chromium的命令行。

Note: This will not affect process.argv. 这不会影响process.argvThe intended usage of this function is to control Chromium's behavior.此功能的预期用途是控制Chromium的行为。

commandLine.appendArgument(value)

  • value string - The argument to append to the command line要附加到命令行的参数

Append an argument to Chromium's command line. 在Chromium的命令行中附加一个参数。The argument will be quoted correctly. 该论点将被正确引用。Switches will precede arguments regardless of appending order.无论追加顺序如何,开关都将位于参数之前。

If you're appending an argument like --switch=value, consider using appendSwitch('switch', 'value') instead.如果您要附加像--switch=value这样的参数,请考虑改用appendSwitch('switch', 'value')

Note: This will not affect process.argv. 这不会影响process.argvThe intended usage of this function is to control Chromium's behavior.此功能的预期用途是控制Chromium的行为。

commandLine.hasSwitch(switch)

  • switch string - A command-line switch命令行开关

Returns返回boolean - Whether the command-line switch is present.命令行开关是否存在。

commandLine.getSwitchValue(switch)

  • switch string - A command-line switch命令行开关

Returns返回string - The command-line switch value.命令行开关值。

Note: When the switch is not present or has no value, it returns empty string.当开关不存在或没有值时,它将返回空字符串。

commandLine.removeSwitch(switch)

  • switch string - A command-line switch命令行开关

Removes the specified switch from Chromium's command line.从Chromium的命令行中删除指定的开关。

Note: This will not affect process.argv. 这不会影响process.argvThe intended usage of this function is to control Chromium's behavior.此功能的预期用途是控制Chromium的行为。