3

Note: This is a question about Windows Terminal, a new command-line shell as of 2019, not Windows Command Prompt command line shell that is included with Windows.

If I am running cmd.exe in Windows Terminal, and I run start cmd, it opens a new command prompt window outside of Windows Terminal.

Is there any way to set Windows Terminal to "intercept" or otherwise harness that command so that it instead opens in a new tab in Windows Terminal (obviously running cmd.exe, in this example)?

Obviously, I can open a new tab with the mouse or a hotkey like Ctrl+Shift+2, but I'd like a way to do so from a batch file.

Patrick Szalapski
  • 241
  • 1
  • 7
  • 22
  • It is difficult to understand your question, try only typing "cmd" in your Terminal. Is that the sort of result you are looking for? – Ecstasy Feb 28 '20 at 15:15
  • No. That starts cmd.exe in the same window and tab. How do I start cmd.exe in a new tab in Windows Terminal? – Patrick Szalapski Feb 28 '20 at 15:17
  • Using "start " always opens a new window of the program for me. What exact version of Windows are you operating on? – Ecstasy Feb 28 '20 at 15:18
  • I am using Windows Terminal, not Command Prompt. I wonder if you aren't aware of Windows Terminal? – Patrick Szalapski Feb 28 '20 at 15:29
  • I am not aware of Windows Terminal. Let me go educate myself really quick. – Ecstasy Feb 28 '20 at 15:30
  • 1
    Might be possible, maybe there is hope using wt.exe. See: https://weblog.west-wind.com/posts/2019/Sep/03/Programmatically-Opening-Windows-Terminal-in-a-Specific-Folder – LPChip Feb 28 '20 at 18:37
  • 1
    okay, wt creates a new terminal window, but you can't get it to make new tabs yet. seems to not respond to the commandline parameters just yet. – LPChip Feb 28 '20 at 18:44

1 Answers1

2

This is possible with Windows Terminal from version 0.9 onwards.

wt -d . ; new-tab -d C:\ pwsh.exe

Opens the Terminal with two tabs. The first is running the default profile starting in the current working directory. The second is using the default profile with pwsh.exe as the "commandline" (instead of the default profile’s "commandline") starting in the C:\ directory.

There are more examples on how to use this in the release notes of Windows Terminal 0.9: https://devblogs.microsoft.com/commandline/windows-terminal-preview-v0-9-release/

Jan W
  • 121
  • Is there any way to open a new tab from inside the terminal itself? – Patrick Szalapski Aug 07 '20 at 19:20
  • 1
    No, Windows Terminal is not yet capable of opening new tabs or panes in an existing instance. See :https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux#open-a-new-profile-instance @PatrickSzalapski – dennohpeter Jan 31 '21 at 17:51
  • Yes, now there is an option: https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux#target-a-specific-window – kaffarell Aug 05 '22 at 12:03
  • Use wt -w 0 nt -d . cmd /k .\my-command.bat if you want to start a command in the old shell. – rakensi Jun 23 '23 at 07:33