linux添加cmd命令行参数,Windows 终端命令行参数 | Microsoft Docs
使用 Windows 終端的命令行參數Using command-line arguments for Windows Terminal
06/18/2020
本文內容
可以使用 wt.exe 從命令行打開 Windows 終端的新實例。You can use wt.exe to open a new instance of Windows Terminal from the command line. 還可以改為使用執行別名 wt。You can also use the execution alias wt instead.
備注
如果從 GitHub 上的源代碼生成了 Windows 終端,則可以使用 wtd.exe 或 wtd 打開該生成。If you built Windows Terminal from the source code on GitHub, you can open that build using wtd.exe or wtd.
命令行語法Command line syntax
wt 命令行接受兩種類型的值:“選項”和“命令” 。The wt command line accepts two types of values: options and commands. “選項”是一系列標志和其他參數,可以將 wt 命令行的行為作為一個整體來控制。Options are a list of flags and other parameters that can control the behavior of the wt command line as a whole. “命令”提供應該實現的操作或操作列表(以分號分隔)。Commands provide the action, or list of actions separated by semicolons, that should be implemented. 如果未指定命令,則默認情況下會將命令指定為 new-tab。If no command is specified, then the command is assumed to be new-tab by default.
wt [options] [command ; ]
若要顯示列出可用命令行參數的幫助消息,請輸入:wt -h、wt --help、wt -? 或 wt /?。To display a help message listing the available command-line arguments, enter: wt -h, wt --help, wt -?, or wt /?.
選項和命令Options and commands
下面是 wt 命令行支持的命令和選項的完整列表。Below is the full list of supported commands and options for the wt command line.
選項Option
說明Description
--help、-h、-?、/?--help, -h, -?, /?
顯示幫助消息。Displays the help message.
--maximized、-M--maximized, -M
以最大化形式啟動終端。Launches the terminal maximized.
--fullscreen、-F--fullscreen, -F
以全屏形式啟動終端。Launches the terminal as full screen.
重要
--maximized、-M 和 --fullscreen、-F 僅在 Windows 終端預覽中可用。--maximized, -M and --fullscreen, -F are only available in Windows Terminal Preview.
命令Command
參數Parameters
說明Description
new-tab
--profile, -p profile-name、--startingDirectory, -d starting-directory、commandline、--title--profile, -p profile-name, --startingDirectory, -d starting-directory, commandline, --title
創建新選項卡。Creates a new tab.
split-pane
-H, --horizontal、-V, --vertical、--profile, -p profile-name、--startingDirectory, -d starting-directory、commandline、--title-H, --horizontal, -V, --vertical, --profile, -p profile-name, --startingDirectory, -d starting-directory, commandline, --title
拆分新窗格。Splits a new pane.
focus-tab
--target, -t tab-index
聚焦于特定選項卡。Focuses on a specific tab.
重要
--title 僅在 Windows 終端預覽中可用。--title is only available in Windows Terminal Preview.
命令行參數示例Command line argument examples
命令可能會略有不同,具體取決于所使用的命令行。Commands may vary slightly depending on which command line you're using.
打開新的配置文件實例Open a new profile instance
若要打開新的終端實例(在此示例中,該命令將打開名為“Ubuntu-18.04”的配置文件),請輸入:To open a new terminal instance, in this case the command will open the profile named "Ubuntu-18.04", enter:
wt -p "Ubuntu-18.04"
wt -p "Ubuntu-18.04"
cmd.exe /c "wt.exe" -p "Ubuntu-18.04"
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止。The /c option tells CMD to terminate after running.
-p 標志用于指定應打開的 Windows 終端配置文件。The -p flag is used to specify the Windows Terminal profile that should be opened. 將“Ubuntu-18.04”替換為已安裝的任何終端配置文件的名稱。Substitute "Ubuntu-18.04" with the name of any terminal profile that you have installed. 這將始終打開一個新窗口。This will always open a new window. Windows 終端尚不能在現有實例中打開新選項卡或窗格。Windows Terminal is not yet capable of opening new tabs or panes in an existing instance.
以一個目錄為目標Target a directory
若要指定應該用作控制臺起始目錄的文件夾(在本例中為 d:\目錄),請輸入:To specify the folder that should be used as the starting directory for the console, in this case the d:\ directory, enter:
wt -d d:\
wt -d d:\
cmd.exe /c "wt.exe" -d d:\
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止。The /c option tells CMD to terminate after running.
多個選項卡Multiple tabs
若要打開具有多個選項卡的新終端實例,請輸入:To open a new terminal instance with multiple tabs, enter:
wt ; ;
wt `; `;
PowerShell 使用分號,用于分隔語句。PowerShell uses a semicolon ; to delimit statements. 若要將分號 ; 解釋為 wt 命令行參數的命令分隔符,則需要使用反引號轉義分號字符。To interpret a semicolon ; as a command delimiter for wt command-line arguments, you need to escape semicolon characters using backticks. PowerShell 還具有停止分析運算符 (--%),這指示它停止解釋它之后的任何內容,并只逐字傳遞。PowerShell also has the stop parsing operator (--%), which instructs it to stop interpreting anything after it and just pass it on verbatim.
cmd.exe /c "wt.exe" \; \;
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止。The /c option tells CMD to terminate after running.
若要打開具有多個選項卡的新終端實例(在本例中為命令提示符配置文件和 PowerShell 配置文件),請輸入:To open a new terminal instance with multiple tabs, in this case a Command Prompt profile and a PowerShell profile, enter:
wt -p "Command Prompt" ; new-tab -p "Windows PowerShell"
wt -p "Command Prompt" `; new-tab -p "Windows PowerShell"
PowerShell 使用分號,用于分隔語句。PowerShell uses a semicolon ; to delimit statements. 若要將分號 ; 解釋為 wt 命令行參數的命令分隔符,則需要使用反引號轉義分號字符。To interpret a semicolon ; as a command delimiter for wt command-line arguments, you need to escape semicolon characters using backticks. PowerShell 還具有停止分析運算符 (--%),這指示它停止解釋它之后的任何內容,并只逐字傳遞。PowerShell also has the stop parsing operator (--%), which instructs it to stop interpreting anything after it and just pass it on verbatim.
cmd.exe /c "wt.exe" -p "Command Prompt" \; new-tab -p "Windows Powershell"
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止,且 \; 正斜杠 + 分號將命令分隔開來。The /c option tells CMD to terminate after running and the \; forward-slash + semicolon separates commands.
多個窗格Multiple panes
若要使用一個選項卡打開一個包含三個窗格(分別運行命令提示符配置文件、PowerShell 配置文件以及運行 WSL 命令行的默認配置文件)的新終端實例,請輸入:To open a new terminal instance with one tab containing three panes running a Command Prompt profile, a PowerShell profile, and your default profile running a WSL command line, enter:
wt -p "Command Prompt" ; split-pane -p "Windows PowerShell" ; split-pane -H wsl.exe
wt -p "Command Prompt" `; split-pane -p "Windows PowerShell" `; split-pane -H wsl.exe
PowerShell 使用分號,用于分隔語句。PowerShell uses a semicolon ; to delimit statements. 若要將分號 ; 解釋為 wt 命令行參數的命令分隔符,則需要使用反引號轉義分號字符。To interpret a semicolon ; as a command delimiter for wt command-line arguments, you need to escape semicolon characters using backticks. PowerShell 還具有停止分析運算符 (--%),這指示它停止解釋它之后的任何內容,并只逐字傳遞。PowerShell also has the stop parsing operator (--%), which instructs it to stop interpreting anything after it and just pass it on verbatim.
cmd.exe /c "wt.exe" -p "Command Prompt" \; split-pane -p "Windows PowerShell" \; split-pane -H wsl.exe
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止,且 \; 正斜杠 + 分號將命令分隔開來。The /c option tells CMD to terminate after running and the \; forward-slash + semicolon separates commands.
-H 標志(或 --horizontal)指示你希望水平拆分窗格。The -H flag (or --horizontal) indicates that you would like the panes to be split horizontally. -V 標志(或 --vertical)指示你希望垂直拆分窗格。The -V flag (or --vertical) indicates that you would like the panes split vertically.
選項卡標題(預覽)Tab title (Preview)
若要打開帶有自定義選項卡標題的新終端實例,可使用 --title 參數。To open a new terminal instance with custom tab titles, use the --title argument. 若要在打開兩個選項卡時設置每個選項卡的標題,請輸入:To set the title of each tab when opening two tabs, enter:
wt --title tabname1 ; new-tab -p "Ubuntu-18.04" --title tabname2
wt --title tabname1 `; new-tab -p "Ubuntu-18.04" --title tabname2
cmd.exe /c "wt.exe" --title tabname1 \; new-tab -p "Ubuntu-18.04" --title tabname2
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止,且 \; 正斜杠 + 分號將命令分隔開來。The /c option tells CMD to terminate after running and the \; forward-slash + semicolon separates commands.
重要
This feature is only available in Windows Terminal Preview.
選項卡焦點Tab focus
若要打開帶有特定焦點選項卡的新終端實例,請使用 -t 標志(或 --target)以及選項卡-索引號。To open a new terminal instance with a specific tab in focus, use the -t flag (or --target), along with the tab-index number. 若要在第一個選項卡中打開默認配置文件,并在第二個選項卡 (-t 1) 中打開焦點“Ubuntu-18.04”配置文件,請輸入:To open your default profile in the first tab and the "Ubuntu-18.04" profile focused in the second tab (-t 1), enter:
wt ; new-tab -p "Ubuntu-18.04" ; focus-tab -t 1
wt `; new-tab -p "Ubuntu-18.04" `; focus-tab -t 1
cmd.exe /c "wt.exe" \; new-tab -p "Ubuntu-18.04" \; focus-tab -t 1
執行別名不適用于 WSL 分發。Execution aliases do not work in WSL distributions. 如果要從 WSL 命令行使用 wt.exe,可以運行 cmd.exe 直接從 CMD 生成它。If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. /c 選項指示 CMD 在運行后終止,且 \; 正斜杠 + 分號將命令分隔開來。The /c option tells CMD to terminate after running and the \; forward-slash + semicolon separates commands.
PowerShell 中多個命令的示例Examples of multiple commands from PowerShell
Windows 終端使用分號字符 ; 作為分隔符來分隔 wt 命令行中的命令。Windows Terminal uses the semicolon character ; as a delimiter for separating commands in the wt command line. 遺憾的是,PowerShell 也使用 ; 作為命令分隔符。Unfortunately, PowerShell also uses ; as a command separator. 若要解決此問題,可以使用以下技巧從 PowerShell 運行多個 wt 命令。To work around this, you can use the following tricks to run multiple wt commands from PowerShell. 在下面的所有示例中,將創建一個新的終端窗口,其中包含三個窗格:一個運行命令提示符,一個運行 PowerShell,最后一個運行 WSL。In all the following examples, a new terminal window is created with three panes - one running Command Prompt, one with PowerShell, and the last one running WSL.
下面的示例使用 Start-Process 命令來運行 wt。The following examples use the Start-Process command to run wt. 如需了解終端為什么使用 Start-Process,請參閱下面的使用 start。For more information on why the terminal uses Start-Process, see Using start below.
單引號括起來的參數Single quoted parameters
在此示例中,wt 參數以單引號(')括起來。In this example, the wt parameters are wrapped in single quotes ('). 如果不計算任何內容,則此語法非常有用。This syntax is useful if nothing is being calculated.
start wt 'new-tab "cmd" ; split-pane -p "Windows PowerShell" ; split-pane -H wsl.exe'
轉義的引號Escaped quotes
將變量中包含的值傳遞到 wt 命令行時,請使用以下語法:When passing a value contained in a variable to the wt command line, use the following syntax:
$ThirdPane = "wsl.exe"
start wt "new-tab cmd ; split-pane -p `"Windows PowerShell`" ; split-pane -H $ThirdPane"
請注意,使用 ` 將 -p 參數中的“Windows PowerShell”的雙引號 (") 轉義給 split-pane 參數。Note the usage of ` to escape the double-quotes (") around "Windows PowerShell" in the -p parameter to the split-pane parameter.
使用 startUsing start
上述所有示例顯式使用 start 啟動終端。All the above examples explicitly used start to launch the terminal.
下面的示例不使用 start 運行命令行。The following examples do not use start to run the command line. 但是,可以通過另外兩種方法來對命令行轉義:Instead, there are two other methods of escaping the command line:
僅對分號進行轉義,使 PowerShell 忽略它們,并將它們直接傳遞到 wt。Only escaping the semicolons so that PowerShell will ignore them and pass them straight to wt.
使用 --%,因此 PowerShell 會將命令行的其余部分視為應用程序的參數。Using --%, so PowerShell will treat the rest of the command line as arguments to the application.
wt new-tab "cmd" `; split-pane -p "Windows PowerShell" `; split-pane -H wsl.exe
wt --% new-tab cmd ; split-pane -p "Windows PowerShell" ; split-pane -H wsl.exe
在這兩個示例中,新創建的 Windows 終端窗口將通過正確分析所有提供的命令行參數來創建窗口。In both of these examples, the newly created Windows Terminal window will create the window by correctly parsing all the provided command-line arguments.
但是目前不建議使用這些方法,因為 PowerShell 會等待新創建的終端窗口關閉,然后再將控制權返回給 PowerShell。However, these methods are not recommended currently, as PowerShell will wait for the newly-created terminal window to be closed before returning control to PowerShell. 默認情況下,在返回到提示符之前,PowerShell 將始終等待 Windows 應用商店應用程序(如 Windows 終端)關閉。By default, PowerShell will always wait for Windows Store applications (like Windows Terminal) to close before returning to the prompt. 請注意,這與命令提示符的行為不同,后者會立即返回到提示符。Note that this is different than the behavior of Command Prompt, which will return to the prompt immediately.
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的linux添加cmd命令行参数,Windows 终端命令行参数 | Microsoft Docs的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为P60洛可可白被“玩坏了” 网友大开
- 下一篇: 2020年光大银行贷款利率