You need to enable JavaScript to run this app. 如何编写脚本在Windows Terminal不同标签页启动两个命令进程
优惠活动
大模型
产品
解决方案
定价
更多

如何编写脚本在Windows Terminal不同标签页启动两个命令进程

实现方法

完全可以通过单个脚本实现需求,你只需要正确使用wt(Windows Terminal 命令行启动工具)的多标签参数即可,常见的踩坑点是不同脚本环境下的分号转义规则差异,以下是不同脚本类型的可直接运行示例:

批处理脚本(.bat/.cmd 格式)

批处理环境中分号不需要额外转义,直接使用;分隔多个new-tab参数即可:

  • 基础示例(第一个标签开 PowerShell,第二个标签开 cmd):
wt new-tab powershell.exe ; new-tab cmd.exe
  • 带自定义启动目录、自定义程序示例:
:: 第一个标签在D:\project目录启动app1.exe,第二个标签在带空格的路径下启动app2.exe
wt new-tab -d D:\project D:\bin\app1.exe ; new-tab -d "D:\我的程序目录" "D:\工具\app2.exe"
  • 程序运行后保留标签不自动关闭示例(给 PowerShell 加-NoExit参数):
wt new-tab powershell.exe -NoExit -Command "D:\test\app1.exe" ; new-tab powershell.exe -NoExit -Command "D:\test\app2.exe"
  • 若提示wt不是内部命令,使用完整路径调用:
"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe" new-tab powershell.exe ; new-tab cmd.exe

PowerShell 脚本(.ps1 格式)

PowerShell 中分号是默认的语句分隔符,需要用反引号`转义分号才能正确传递给wt命令:

  • 基础示例:
wt new-tab powershell.exe `; new-tab cmd.exe
  • 带自定义路径和程序示例:
wt new-tab -d "D:\我的项目" node index.js `; new-tab -d "C:\工作目录" python main.py
  • 无wt命令时的完整路径调用方式:
& $env:LOCALAPPDATA\Microsoft\WindowsApps\wt.exe new-tab powershell.exe `; new-tab cmd.exe

内容的提问来源于stack exchange,提问作者Emilio Numazaki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 20:03:04