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

10,122
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.

Share:
10,122

Related videos on Youtube

run_the_race
Author by

run_the_race

Updated on December 30, 2020

Comments

  • run_the_race
    run_the_race almost 2 years

    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?

    • run_the_race
      run_the_race
      @GerhardBarnard thanks for the reply, that is the kind of thing I am looking for, however wt.exe dir launches wt but shows an error: [error 0x80070002 when launching `dir']. I have set cmd as the default profile for this example. If wt.exe dir that works for you, then maybe there is something wrong with my system.
    • JosefZ
      JosefZ
      Please read the minimal reproducible example article again. For instance: "It doesn't work" isn't descriptive enough to help people understand your problem. From this point of view I can understand downvoters - although I myself never downvote without further explanation in a comment. And your approach is asking for trouble…
  • run_the_race
    run_the_race over 2 years
    Thank you that is brillant! I don't know how you figured it out. I read the the windows doc and wt --help, and googled, and didnt get a clue at all.
  • run_the_race
    run_the_race over 2 years
    Add thanks to your link, for anyone looking for the power shell equivalent: Start-Process wt.exe -ArgumentList "PowerShell.exe", "-NoExit", "-Command", "dir"
  • ttugates
    ttugates almost 2 years
    The new-tab param seems to open a new window for me.
  • Albena Kertova
    Albena Kertova over 1 year
    Awesome, thank you! You can totally automate your routines with this one!

Related