How to open new tab with running specific command in Poweshell (Windows Terminal)? #13552

Closed
opened 2026-01-31 03:45:39 +00:00 by claunia · 9 comments
Owner

Originally created by @rajan-31 on GitHub (Apr 19, 2021).

Description of the new feature/enhancement

What I want is open new tab having Powershell and running 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 error,

[error 0x80070002 when launching `npm run local']

Is it possible and how?

Proposed technical implementation details (optional)

Not Applicable.

Originally created by @rajan-31 on GitHub (Apr 19, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement What I want is open new tab having Powershell and running 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 error, [error 0x80070002 when launching `npm run local'] Is it possible and how? <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) Not Applicable. <!-- A clear and concise description of what you want to happen. -->
Author
Owner

@zadjii-msft commented on GitHub (Apr 19, 2021):

Is npm on your PATH? Note that when you set the commandline like this, WT isn't going to launch powershell first, then run npm .... The Terminal is literally going to call CreateProcess("npm run local"...

@zadjii-msft commented on GitHub (Apr 19, 2021): Is `npm` on your `PATH`? Note that when you set the commandline like this, WT isn't going to launch powershell first, then run `npm ...`. The Terminal is literally going to call `CreateProcess("npm run local"...`
Author
Owner

@rajan-31 commented on GitHub (Apr 19, 2021):

Is npm on your PATH?
Yes.

I got what you are saying.

Is there a way to get it working (or any workaround)?


I found a solution for Command Prompt using,

wt --window 0 -p "Windows Powershell" -d "%cd%" powershell -noExit "npm run local"

I did lot of research to know how this is working so that to use same logic for Powershell, but I was not able to get anything working.

Is there Powershell equivalent of this?

@rajan-31 commented on GitHub (Apr 19, 2021): Is `npm` on your `PATH`? **Yes.** I got what you are saying. Is there a way to get it working (or any workaround)? --- I found a solution for **Command Prompt** using, `wt --window 0 -p "Windows Powershell" -d "%cd%" powershell -noExit "npm run local"` I did lot of research to know how this is working so that to use same logic for Powershell, but I was not able to get anything working. **Is there Powershell equivalent of this?**
Author
Owner

@DHowett commented on GitHub (Apr 19, 2021):

Is npm on your PATH?
Yes.

Sorry, is npm on the system or user PATH before it is modified by your shell?

@DHowett commented on GitHub (Apr 19, 2021): > Is `npm` on your `PATH`? > **Yes.** > Sorry, is `npm` on the system or user `PATH` _before it is modified by your shell_?
Author
Owner

@zadjii-msft commented on GitHub (Apr 20, 2021):

Does wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local" not work in powershell?

actually, wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local" might just work in both...

@zadjii-msft commented on GitHub (Apr 20, 2021): Does `wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local"` not work in powershell? actually, `wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local"` might just work in _both_...
Author
Owner

@rajan-31 commented on GitHub (Apr 20, 2021):

Does wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local" not work in powershell?

actually, wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local" might just work in both...

Yes, 1st command is working in Powershell & 2nd command is working in both.

Examples like above commands i.e. Open new tab with running specific command in Poweshell/Command Prompt,
should be in Official documentation. Because there no other way to know these tricks.
(I would like to help.)

It's a request.

Also, I found similar questions on websites like Stack Overflow.


The real reason for asking this question was to be able to do this,

wt -w 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"`; sp -H -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"`; nt -p "Windows Powershell" -d . powershell -noExit "npm run local"

It will save a lot of time, instead of manually running every command whenever we start the app development.

@rajan-31 commented on GitHub (Apr 20, 2021): > Does `wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local"` not work in powershell? > > actually, `wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local"` might just work in _both_... **Yes, 1st command is working in Powershell & 2nd command is working in both.** Examples like above commands i.e. Open new tab with running specific command in Poweshell/Command Prompt, should be in Official documentation. Because there no other way to know these tricks. (I would like to help.) It's a request. Also, I found similar questions on websites like Stack Overflow. --- The real reason for asking this question was to be able to do this, ```wt -w 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"`; sp -H -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"`; nt -p "Windows Powershell" -d . powershell -noExit "npm run local"``` It will save a lot of time, instead of manually running every command whenever we start the app development.
Author
Owner

@zadjii-msft commented on GitHub (Apr 20, 2021):

should be in Official documentation

It totally is, but thanks for the suggestion!

@zadjii-msft commented on GitHub (Apr 20, 2021): > should be in Official documentation It [totally is](https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows#multiple-tabs-and-panes), but thanks for the suggestion!
Author
Owner

@xsnowemployee commented on GitHub (Dec 15, 2021):

Does wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local" not work in powershell?
actually, wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local" might just work in both...

Yes, 1st command is working in Powershell & 2nd command is working in both.

Examples like above commands i.e. Open new tab with running specific command in Poweshell/Command Prompt, should be in Official documentation. Because there no other way to know these tricks. (I would like to help.)

It's a request.

Also, I found similar questions on websites like Stack Overflow.

The real reason for asking this question was to be able to do this,

wt -w 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"`; sp -H -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"`; nt -p "Windows Powershell" -d . powershell -noExit "npm run local"

It will save a lot of time, instead of manually running every command whenever we start the app development.

If I want to redirect to different directory and then run those commands is there any way ?
Second is there anyway if I always open same location and same tabs so I set in somewhere in config?

@xsnowemployee commented on GitHub (Dec 15, 2021): > > Does `wt --window 0 -p "Windows Powershell" -d "$pwd" powershell -noExit "npm run local"` not work in powershell? > > actually, `wt --window 0 -p "Windows Powershell" -d . powershell -noExit "npm run local"` might just work in _both_... > > **Yes, 1st command is working in Powershell & 2nd command is working in both.** > > Examples like above commands i.e. Open new tab with running specific command in Poweshell/Command Prompt, should be in Official documentation. Because there no other way to know these tricks. (I would like to help.) > > It's a request. > > Also, I found similar questions on websites like Stack Overflow. > > The real reason for asking this question was to be able to do this, > > `` wt -w 0 -p "Windows Powershell" -d . powershell -noExit "npm run startMongo"`; sp -H -p "Windows Powershell" -d . powershell -noExit "npm run gulp-watch"`; nt -p "Windows Powershell" -d . powershell -noExit "npm run local" `` > > It will save a lot of time, instead of manually running every command whenever we start the app development. If I want to redirect to different directory and then run those commands is there any way ? Second is there anyway if I always open same location and same tabs so I set in somewhere in config?
Author
Owner

@zadjii-msft commented on GitHub (Dec 15, 2021):

Second is there anyway if I always open same location and same tabs so I set in somewhere in config

You might be interested in startingDirectory and "firstWindowPreference": "persistedWindowLayout"

@zadjii-msft commented on GitHub (Dec 15, 2021): > Second is there anyway if I always open same location and same tabs so I set in somewhere in config You might be interested in [`startingDirectory`](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-general#starting-directory) and [`"firstWindowPreference": "persistedWindowLayout"`](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/startup#behavior-when-starting-a-new-terminal-session-preview)
Author
Owner

@GregWoods commented on GitHub (Aug 23, 2024):

should be in Official documentation

It totally is, but thanks for the suggestion!

Really?
The simple and fairly obvious use-case isn't obvious to me. The examples are mixing multiple features of wt, so IMO the simple use-case is lost. I'd love to see the simplest example of "open a new tab and run this this command" (note: not a "wt" command, but something you would type in yourself, like "yarn start")

It could be that I'm stupid... but it seems I'm not the only one, which kinda feels like the docs could be improved a little?

@GregWoods commented on GitHub (Aug 23, 2024): > > should be in Official documentation > > It [totally is](https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows#multiple-tabs-and-panes), but thanks for the suggestion! Really? The simple and fairly obvious use-case isn't obvious to me. The examples are mixing multiple features of wt, so IMO the simple use-case is lost. I'd love to see the simplest example of "open a new tab and run this this command" (note: not a "wt" command, but something you would type in yourself, like "yarn start") It could be that I'm stupid... but it seems I'm not the only one, which kinda feels like the docs could be improved a little?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#13552