After the #5090 update it would be great if we could do something like this:
wt "yarn some-command"; split-pane -V -d ./some-dir "yarn some-other-command"
It would enable us to execute commands in the Windows Terminal sessions and it can be used as any normal console terminal right now.
Uh, that's literally how it's supposed to work now... This doc has some examples.
Are you seeing some sort of error when you try that? Are you running the commandline from cmd, powershell, pwsh, bash, something else?
@zadjii-msft The examples you gave are for different terminal programs to be assigned to the different views.
My example with yarn was that yarn manager had to be executed with the default terminal profile, not that yarn itself is a terminal.
wt cmd "dir" -> WT window running a cmd instance and no dir command execution.
wt "dir" -> [error 0x80070002 when launching `dir']
My default terminal profile is using git bash, but I've tested it out also with cmd.
oh oh oh I think I see what's happening. yarn isn't a Windows executable, it's a WSL one, right? The commandline argument is just a _Windows_ commandline to start, not "a commandline to run in the profile that's spawned".
You can also see this in the dir example you gave. dir is a "cmd intrinsic", which means it's a feature of cmd.exe itself, there's not a dir.exe that cmd spawns. So you can't just CreateProcess("dir",...), because there _isn't a dir.exe to spawn_. You need to launch cmd to be able to run dir. As a wt commandline, that'd be something like wt cmd /k dir.
So, for the yarn case, you'd probably want wt wsl yarn some-command
EDIT: Okay I'm seeing now the update to your post to include notes about "git bash". I'm not super familiar with how git bash works unfortunately, but I'd presume that you'd need to use the following commandline:
wt "C:/Program Files/Git/bin/bash.exe" yarn some-command
Here, I'm assuming that "C:/Program Files/Git/bin/bash.exe" yarn some-command will run yarn some-command in git bash. I don't know if that path is totally appropriate, or if bash.exe requires extra arguments to launch a child process appropriately.
I've tested it. It works, but every time I have to enter the full path of the command line terminal, before passing commands to it. It would be great the fire up the default if none are present. :)
So that gets complicated.
wsl ping (contrived example but gets the point across)? Then, a commandline of wsl ping yarn some-command would certainly not work.{profile.commandline} {commandline from args}. I'm sure there's another thread about this somewhere, but IIRC we determined that it's generally impossible to tell if a particular commandline will resolve to a process without just trying to _start the process_. There's maybe room for us to add something like --appendCommandline [arguments...] that behaves the way you're expecting. For that reason, I'm gonna leave this issue open and tack it onto the commandline args megathread. I hate that name for it, so it'd probably need a proper spec review, but I don't hate the _idea_ of it.
Just an idea:
What if the unified way of starting a specific command line terminal is wt -p "Windows PowerShell" | cmd | <any-exe-in-PATH> | <path-to-exe>, if -p is not specified wt usese the default profile and all added arugments after that are run in the profile.
Your idea with --appendCommandline also sounds okay. Maybe you and your team would have to decide which scenario is more common/sensible to implement.
I'd personally like to see support for adding command line arguments for the profile after launch. This way once a tab is launched we can have it so that it automatically executes a command in that terminal window.
@Ruegen cmd /k command1 && command; powershell -noexit -c command1 && command2; bash -c "command1; exec bash -l"
This seams to work for running command in a new open window.
wt ubuntu run "ls / && bash"
This will run Ubuntu WSL and then execute ls / and then leave bash interactive shell open. Without bash at the end it just exits.
I've tested it. It works, but every time I have to enter the full path of the command line terminal, before passing commands to it. It would be great the fire up the default if none are present. :)
I believe the reason for this might be that "C:/Program Files/Git/bin/bash.exe" is used, but the user to use it has not been "logged in". What I mean by that is, take this for example. This is my GitBash profile:
{
"guid": "{00000000-0000-0000-0000-000000000001}",
"acrylicOpacity": 0.9,
"useAcrylic": true,
"closeOnExit": true,
"colorScheme": "Solarized Dark",
"commandline": "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" --login -i -l",
"cursorColor": "#FFFFFF",
"cursorShape": "bar",
"fontFace": "Consolas",
"fontSize": 10,
"historySize": 9001,
"icon": "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
"name": "GitBash",
"padding": "15, 5, 10, 55",
"snapOnInput": true,
"startingDirectory": "%USERPROFILE%\\Desktop"
},
Notice how it has --login -i -l. Without that, my bash profile is not loaded and as a result I don't have my aliases for example. And perhaps the same reason is causing something as simple as ls to fail.

Although, probably I'm totally off the ball on this one.
It would be incredibly useful to open a Windows Terminal (wsl) profile from the commandline and run a command inside afterwards. Something like
wt -p Debian "cd ~/my-project & npm start"
I could create shortcuts to projects and stuff, start environments with a single click. I tried many different combinations of the wt command, but nothing worked. Or am I missing something?
Thanks for the help!
Definitely would be helpful to have this. I have several things that need to be started for my local development, so ideally I want to have a one-liner that starts it all in separate tabs/panes.
I know I could theoretically solve this on the OS level with eg. Docker or some process manager, but that's a pretty advanced stuff for a long term Windows user :)
Most helpful comment
I'd personally like to see support for adding command line arguments for the profile after launch. This way once a tab is launched we can have it so that it automatically executes a command in that terminal window.