Windows Terminal多窗格执行指定命令的可行性及实现方法咨询
Absolutely feasible! The issue with your current command boils down to how you're passing commands to each shell instance—Windows Terminal's wt tool needs you to account for how each shell (like Command Prompt) processes command-line inputs.
Let me break down the problem and fix this for you:
The core snag: When using
-cwith Command Prompt (cmd.exe), you can't just pass the raw command string directly.cmd.exerequires its own/cflag to execute a sequence of commands and handle them properly. Your current command skips this step, which is why it's not working as expected.Corrected command: Here's the adjusted version that will launch both panes with their respective commands running:
wt -p "Command Prompt" -d <your-project-path> -c "/c cls && php artisan serve" ; split-pane -p "Command Prompt" -H -d <your-project-path> -c "/c npm run watch"Just replace
<your-project-path>with your actual working directory (e.g.,C:\dev\my-laravel-app).If you prefer PowerShell for the first pane: If you want to run the
php artisan servecommand in PowerShell instead of Command Prompt, note thatclsis an alias forClear-Hostthere. PowerShell accepts command strings directly via-c, so you'd use this version:wt -p "Windows PowerShell" -d <your-project-path> -c "Clear-Host && php artisan serve" ; split-pane -p "Command Prompt" -H -d <your-project-path> -c "/c npm run watch"Quick extra tips:
- If you want the panes to stay open after their commands finish (e.g., if
php artisan servestops and you want to keep the window to run other commands), swap/cwith/kfor Command Prompt, or add; pauseto the end of the PowerShell command. - Double-check that your profiles are named correctly (e.g., "Command Prompt" is the default name for the cmd profile—if you renamed it, use that exact name in the
-pflag).
- If you want the panes to stay open after their commands finish (e.g., if
内容的提问来源于stack exchange,提问作者Mr.Singh

