I made a pretty simple PowerShell script to run my project.
$path = './Desktop/Code/projects'
$windowId = 'app'
$wtCommand = 'split-pane'
$command = "wt -M -w $windowId pwsh -NoExit -c 'cd $path/app/client && npm run dev' && " +
"wt -M -w $windowId $wtCommand -V pwsh -NoExit -c 'cd $path/app/backend && air' && " +
"wt -M -w $windowId $wtCommand -V pwsh -NoExit -c 'cd $path/app/admin && npm run dev' && " +
"wt -M -w $windowId $wtCommand -H pwsh -NoExit -c 'cd $path/Auth/server && air' && " +
"wt -M -w $windowId $wtCommand -V pwsh -NoExit -c 'cd $path/service_1 && air' && " +
"wt -M -w $windowId $wtCommand -V pwsh -NoExit -c 'cd $path/service_2 && docker run -p 8090:8090 service_2:latest'"
Invoke-Expression $command
And it ALWAYS opens exactly two tabs, but sometimes it opens all the panes correctly, sometimes don't split the editor at all, running just random two apps. Really random behavior.
But if I change command to the new-tab instead of the split-pane, it will open all the 6 tabs every time just fine.
The terminal version is 1.19.10302.0. I've tried pre-release too, same there.
I suspect that launching multiple
wt.exeinstances, as you've tried - each of which launches asynchronously - can lead to race conditions.You can avoid the problem - while also speeding up the operation - if you use a single
wt.execall and pass it all subcommands at once, separated with;:Note:
Because
;is a metacharacter in PowerShell (statement separator), it is escaped as`;For readability, the
wt.execall is broken into multiple lines, which requires a line-ending`for line-continuation (note that it must be the very last character on each interior line).Direct invocation of
wt.exeis used in lieu of yourInvoke-Expressionapproach:Invoke-Expression(iex) should generally be avoided; except in unusual circumstances, don't use it to invoke an external program or PowerShell script / command.Direct invocation necessitated switching the individual
-carguments to expandable (interpolating), double-quoted string ("...") strings to ensure interpolation of the$pathreferences.