5

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
  • 1,730
  • 17
  • 25
  • So what is stopping you from attempting this? – Gerhard Jul 10 '20 at 06:25
  • Please [edit] your question to provide a [mcve]. – JosefZ Jul 10 '20 at 07:55
  • @JosefZ, minimal reproduceable example is opening cmd.exe and typing wt. I don't understand what more example code is required, could you explain please? In bash you can do bash -c some_command. With windows terminal how does one do the same thing? – run_the_race Jul 10 '20 at 08:04
  • @GerhardBarnard Passing an executable argument to windows terminal as stated in the question. Thats the only part. – run_the_race Jul 10 '20 at 08:05
  • And why is everyone down voting, this is a legitimate question I have been stuck on for a long time, and researched as far as I could. – run_the_race Jul 10 '20 at 08:11
  • 1
    Please read the _[mcve]_ 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… – JosefZ Jul 10 '20 at 08:29
  • But I am.unable.to reproduce your problem because I have non of the detail that I require as you did not provide any. See our predicament? – Gerhard Jul 10 '20 at 08:34
  • @GerhardBarnard I have edited the question, is there any more detail you require? – run_the_race Jul 10 '20 at 08:39
  • @JosefZ Added a minimal example, and an explaination of what doesn't work. – run_the_race Jul 10 '20 at 08:53
  • given the example you want and not an explanation of exactly your goal is, what is wrong with `wt.exe dir` ? it will launch `wt` with the command and close it again. – Gerhard Jul 10 '20 at 09:04
  • 1
    @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. – run_the_race Jul 10 '20 at 09:51
  • @Gerhard - `wt.exe dir` shows an error for me as well. Can you confirm your suggested command `wt.exe dir` typed into wt console does in fact do what you suggest without error? – ttugates Jan 19 '21 at 14:39

1 Answers1

12
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.

JosefZ
  • 22,747
  • 4
  • 38
  • 62
  • 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 Jul 10 '20 at 10:39
  • 2
    Add thanks to your link, for anyone looking for the power shell equivalent: `Start-Process wt.exe -ArgumentList "PowerShell.exe", "-NoExit", "-Command", "dir"` – run_the_race Jul 10 '20 at 10:41
  • 1
    The `new-tab` param seems to open a new window for me. – ttugates Jan 19 '21 at 14:40