What I want is to open a new tab having Powershell and running a specific command (in my case "npm run local").
I was expecting this will work,
wt -w 0 -p "Windows Powershell" npm run local
But, it gives an error,
[error 0x80070002 when launching `npm run local']
Is it possible and how?
*Note: I have done a lot of research and also read the official documentation, but I was not able to find a way.
I found the best/recommended solution from Windows Terminal developers.
Answer on GitHub
For both Command Prompt and Powershell.
wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local"
Only for Powershell.
wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local"
The best use of this feature while running commands for development, in my case
For Powershell
wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"`; split-pane --horizontal -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"`; new-tab -p "Windows Powershell" -d . powershell -noExit "npm run local"
For Command Prompt
wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"; split-pane --horizontal -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"; new-tab -p "Windows Powershell" -d . powershell -noExit "npm run local"
Running Get-Command npm
shows that npm
is actually npm.cmd
, so a CMD interpreted script, not PowerShell. When run directly at the command-line, PowerShell is okay with leaving the extension off, but when passed through a Windows Terminal profile, the extension appears to be required:
wt -w 0 -d . -p "Windows PowerShell" npm.cmd init
wt -w 0 -d . -p "Command Prompt" npm.cmd init
(Edit: -d .
added per your comment. Without that, as you pointed out, it will always default to the %userprofile%
directory).
That said, it seems from your comment that your use-case is to keep the tab open after the process completes. In that case ...
wt -w 0 -d . -p "Windows PowerShell" cmd /k npm run local
wt -w 0 -d . -p "Command Prompt" cmd /k npm run local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With