使用 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相关推荐

  1. linux挂起 终端连不上吗,Linux系统11个不能不知道的终端命令

    Linux系统下有很丰富的终端命令,实际上这些命令可以看做是快捷键.如果知道这些命令,使用Linux系统无疑会变得更加方便.本文就来介绍一下Linux系统11个你不能不知道的终端命令. 1. 命令行日 ...

  2. Linux常用命令笔记与Windows部分命令

    Linux命令 1.帮助命令 1.1 man获得帮助信息 eg:查看ls命令的帮助信息 man ls 1.2 help获得shell内置命令的帮助信息 mv命令(移动文件或重命名) 重命名:(将文件f ...

  3. linux ftp cmd被动模式,如何在Windows命令提示符下使用被动FTP模式?

    如何在Windows命令提示符下使用被动FTP模式? 在Ubuntu quote pasv中,被动模式可以正常工作. 在Windows中我该如何做? 我尝试使用quote pasv,但出现以下错误: ...

  4. Security: Inside Windows Vista User Account Control | Microsoft Docs

    原文地址:Security: Inside Windows Vista User Account Control | Microsoft Learn Security: Inside Windows ...

  5. macbook 终端命令怎么使用_mac终端命令大全 苹果入门

    OSX 的文件系统6 U. w1 K( g3 y$ F 七度苹果电脑软件 OSX 采用的Unix文件系统,所有文件都挂在跟目录 / 下面,所以不在要有Windows 下的盘符概念. # G" ...

  6. 服务器远程桌面参数,windows远程桌面mstsc 参数

    windows远程桌面(mstsc)非常的方便,简直就是局域网神器. 这里记录下mstsc 对应的参数 [Window Title] 远程桌面连接用法 [Content] MSTSC [] [/v:] ...

  7. star ccm 报java错误_在 Linux VM 上运行 STAR-CCM+ 与 HPC Pack - Azure Virtual Machines | Microsoft Docs...

    在 Azure 中的 Linux RDMA 群集上运行 STAR-CCM+ 和 Microsoft HPC Pack 09/13/2016 本文内容 重要 经典 VM 将于 2023 年 3 月 1 ...

  8. 在 Windows 10 上安装 WSL | Microsoft Docs 转

    https://docs.microsoft.com/zh-cn/windows/wsl/install-win10

  9. Windows 终端配置(powershellcmdgit bash等等)

    Windows 终端配置(powershell/cmd/git bash等等) author:onceday date:2022年6月5日 特别提示:本内容主要收集整理于:微软-windows终端文档 ...

最新文章

  1. 互联网协议 — IPv4 — CIDR 网络地址表示法
  2. 关于不能远程连接Linux中Mysql数据库的问题
  3. 北京python培训班价格-北京Python培训班,为什么Python超适合小白学习
  4. Graph Embedding方案之DeepWalk
  5. Vue2.x—理解vuex核心概念action(使用到ES6的变量的解构赋值)
  6. .Net之Swagger基础使用
  7. 4g内存 堆内存分配多少_我需要多少内存
  8. 什么是堆什么是栈以及两者区别特点
  9. java B2B2C Springcloud仿淘宝电子商城系统-spring cloud 框架原理
  10. 3.Knockout.Js(属性绑定)
  11. 国外六大免费Linux备份工具
  12. 8051 r0-r7 是什么
  13. 【RPC】远程过程调用
  14. top工具全字段解析+实战(一)
  15. java阴阳师抽卡概率_《阴阳师》手游随机抽取类玩法概率公示
  16. 如何观察一棵树 - 笔记
  17. Generative Adversarial Networks in Computer Vision: A Survey and Taxonomy(计算机视觉中的GANs:综述与分类)
  18. oracle查询第三行,oracle层次化查询(行政区划三级级联)
  19. Cocos2d-X资源网站索引
  20. 连表查询join使用方法详解

热门文章

  1. Seaborn初学指南
  2. 文献记录(part16)--Learning Bayesian Network Classifiers: Searching in a Space of Partially ...
  3. cmd长ping记录日志和时间_Gin 框架系列 — 路由中间件:日志记录
  4. 2022年Python数据分析的宝藏地带
  5. Jerry 的 SAP 技术交流群里讨论的技术问题都会同步到这个帖子里
  6. 如何修改 pdf 文件默认的显示图标
  7. SAP Commerce Cloud WCMS 里的 home 页面和 SAP Spartacus Page API 返回的数据比较
  8. 如何修改Github已经提交的commit里的提交者用户名和提交者邮箱
  9. All cached global options setting for WordPress
  10. GM6 1.38.1 start up debug - share memory