Start window's terminal from CLI and pass in an executable command to run

run_the_race picture run_the_race · Jul 10, 2020 · Viewed 6.9k times · Source

I can start Windows Terminal with wt. I have read Windows terminal docs on command line arguments, and it just covers passing an argument for setting up terminal panes, not passing in actual executable commands.

e.g. Minimal reproducible example: Requires Windows Terminal installed: Open a cmd prompt in windows and type:

dir | wt

This starts the windows terminal, but it does not receive the dir command. How does one pass the executable command to Windows Terminal?

Answer

JosefZ picture JosefZ · Jul 10, 2020
wt new-tab -p "Command Prompt" -d "%cd%" cmd /k dir
  • You can omit new-tab (its a default command).
  • Omitting -d "%cd%" seems to be equivalent to -d "%USERPROFILE%".
  • You can omit -p "Command Prompt" if your default profile is set to the cmd.exe profile. Check wt settings in the following file (Windows):
%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

Try a more complex command than dir, for instance

wt new-tab -p "Command Prompt" -d "%cd%" cmd /k "dir & type "%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json""

Please check the How to pass commands into the shell opened in new Windows Terminal thread as well.