如何在Windows Terminal批处理脚本中自动执行yarn start:local?
在Windows Terminal打开目录后自动执行yarn start:local的解决方案
你需要修改Windows Terminal的启动命令,明确指定切换目录后执行yarn start:local——-d参数仅用于设置工作目录,无法直接附加执行命令,这是你之前尝试失败的原因。以下是针对现有脚本的修改方案:
方案1:适用于CMD类型的profile
单标签页命令
cmd.exe /c wt.exe --window 0 new-tab --profile "RAN" --title "Components" --tabColor "#8AD8FF" --colorScheme "One Half Dark" cmd /k "cd /d C:\RAN\components-page && yarn start:local"
多窗格命令
cmd.exe /c wt.exe --window 0 new-tab --profile "RAN" --title "Address" --tabColor "#9C37FF" --colorScheme "One Half Dark" cmd /k "cd /d C:\RAN\address-page && yarn start:local" ; split-pane -V -p "RAN" --title "Address Info" --tabColor "#9C37FF" cmd /k "cd /d C:\RAN\address-info-page && yarn start:local"
- 细节说明:
cmd /k用于执行命令后保持终端窗口打开;cd /d确保跨盘符切换目录;&&保证前一个命令执行成功后再运行yarn start:local。
方案2:适用于PowerShell类型的profile
如果你的"RAN" profile默认使用PowerShell,替换为以下命令:
单标签页命令
cmd.exe /c wt.exe --window 0 new-tab --profile "RAN" --title "Components" --tabColor "#8AD8FF" --colorScheme "One Half Dark" powershell -NoExit -Command "Set-Location 'C:\RAN\components-page'; yarn start:local"
多窗格命令
cmd.exe /c wt.exe --window 0 new-tab --profile "RAN" --title "Address" --tabColor "#9C37FF" --colorScheme "One Half Dark" powershell -NoExit -Command "Set-Location 'C:\RAN\address-page'; yarn start:local" ; split-pane -V -p "RAN" --title "Address Info" --tabColor "#9C37FF" powershell -NoExit -Command "Set-Location 'C:\RAN\address-info-page'; yarn start:local"
- 细节说明:
powershell -NoExit确保执行命令后窗口不关闭;Set-Location用于切换工作目录,分号分隔连续执行的命令。
内容的提问来源于stack exchange,提问作者Rene A
相关产品推荐
相关产品推荐

