wt support run command in application #6802

Closed
opened 2026-01-31 00:47:31 +00:00 by claunia · 19 comments
Owner

Originally created by @minhluan259 on GitHub (Mar 10, 2020).

Description of the new feature/enhancement

How to start wt with bash like this:
C:\Windows\System32\cmd.exe /C start wt C:\test.sh value1

Proposed technical implementation details (optional)

test.sh
echo "Value: $1"

Originally created by @minhluan259 on GitHub (Mar 10, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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 How to start wt with bash like this: C:\Windows\System32\cmd.exe /C start wt C:\test.sh value1 <!-- 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) test.sh echo "Value: $1" <!-- A clear and concise description of what you want to happen. -->
Author
Owner

@zadjii-msft commented on GitHub (Mar 10, 2020):

I'm sorry, what are you asking for?

As of 0.9, Windows Terminal supports commandline arguments for a bunch of different scenarios. It should be as easy as running wt C:\test.sh value1

Are you trying to open a new tab in an existing WT window?

Are you trying to change the commandline of a profile so that it will run a script like test.sh (instead of powershell for example)?

Are you trying to use bash on WSL? On Cygwin? Git bash?

@zadjii-msft commented on GitHub (Mar 10, 2020): I'm sorry, what are you asking for? As of 0.9, Windows Terminal supports [commandline arguments](https://github.com/microsoft/terminal/blob/master/doc/user-docs/UsingCommandlineArguments.md) for a bunch of different scenarios. It should be as easy as running `wt C:\test.sh value1` Are you trying to open a new tab in an existing WT window? Are you trying to change the `commandline` of a profile so that it will run a script like `test.sh` (instead of `powershell` for example)? Are you trying to use `bash` on WSL? On Cygwin? Git bash?
Author
Owner

@minhluan259 commented on GitHub (Mar 10, 2020):

I'm using v0.9.

I'm trying to use bash on cmd, gitbash and cygwin
wt new-tab -p "cmd" C:\test.sh value1
wt new-tab -p "Git Bash" C:\test.sh value1
wt new-tab -p "Bash" C:\test.sh value1

All have the same issue
image
image
image

@minhluan259 commented on GitHub (Mar 10, 2020): I'm using v0.9. I'm trying to use bash on cmd, gitbash and cygwin wt new-tab -p "cmd" C:\test.sh value1 wt new-tab -p "Git Bash" C:\test.sh value1 wt new-tab -p "Bash" C:\test.sh value1 All have the same issue ![image](https://user-images.githubusercontent.com/7834473/76322283-c6dc2280-6315-11ea-933c-dc2630f241c5.png) ![image](https://user-images.githubusercontent.com/7834473/76322864-7a451700-6316-11ea-849d-e7672a467532.png) ![image](https://user-images.githubusercontent.com/7834473/76322878-816c2500-6316-11ea-8813-33672bb21c74.png)
Author
Owner

@zadjii-msft commented on GitHub (Mar 10, 2020):

How would you normally run that script, from a cmd.exe window? Probably something like c:\path\to\bash.exe c:\test.sh value1 right? If that's the case, you'll need the following commandline:

wt c:\path\to\bash.exe c:\test.sh value1

What's happening when you run wt new-tab -p "Git Bash" C:\test.sh value1 is the Terminal is trying to run your "Git Bash" profile, but with a commandline of C:\test.sh value1 instead of what the usual commandline is for that profile.

@zadjii-msft commented on GitHub (Mar 10, 2020): How would you normally run that script, from a cmd.exe window? Probably something like `c:\path\to\bash.exe c:\test.sh value1` right? If that's the case, you'll need the following commandline: `wt c:\path\to\bash.exe c:\test.sh value1` What's happening when you run `wt new-tab -p "Git Bash" C:\test.sh value1` is the Terminal is trying to run your "Git Bash" profile, but with a commandline of `C:\test.sh value1` instead of what the usual `commandline` is for that profile.
Author
Owner

@minhluan259 commented on GitHub (Mar 10, 2020):

wt C:\cygwin64\bin\bash C:\test.sh value1
If I run on cmd, it opens the command window and auto close very quick
If I run on Cygwin64
it displays error
bash: /cygdrive/c/Users/minhl/AppData/Local/Microsoft/WindowsApps/wt: Permission denied

@minhluan259 commented on GitHub (Mar 10, 2020): wt C:\cygwin64\bin\bash C:\test.sh value1 If I run on cmd, it opens the command window and auto close very quick If I run on Cygwin64 it displays error bash: /cygdrive/c/Users/minhl/AppData/Local/Microsoft/WindowsApps/wt: Permission denied
Author
Owner

@minhluan259 commented on GitHub (Mar 10, 2020):

All I want is open Window Terminal with custom bash command via WinSCP
C:\Windows\System32\cmd.exe /C start wt new-tab -p "Bash" /cygdrive/c/Users/minhl/ssh.sh !U !@ !P
image

@minhluan259 commented on GitHub (Mar 10, 2020): All I want is open Window Terminal with custom bash command via WinSCP C:\Windows\System32\cmd.exe /C start wt new-tab -p "Bash" /cygdrive/c/Users/minhl/ssh.sh !U !@ !P ![image](https://user-images.githubusercontent.com/7834473/76327808-0bb78780-631d-11ea-8a3d-0f2b917c8d3d.png)
Author
Owner

@zadjii-msft commented on GitHub (Mar 10, 2020):

wt C:\cygwin64\bin\bash C:\test.sh value1
If I run on cmd, it opens the command window and auto close very quick

That sounds like the script is terminating, and the terminal is closing in response to the last tab closing.

I'm not really sure how ssh.sh is supposed to work, but I'd guess that the following would work:

wt C:\cygwin64\bin\bash /cygdrive/c/Users/minhl/ssh.sh !U !@ !P

@zadjii-msft commented on GitHub (Mar 10, 2020): > `wt C:\cygwin64\bin\bash C:\test.sh value1` > If I run on cmd, it opens the command window and auto close very quick That sounds like the script is terminating, and the terminal is closing in response to the last tab closing. I'm not really sure how `ssh.sh` is supposed to work, but I'd guess that the following would work: `wt C:\cygwin64\bin\bash /cygdrive/c/Users/minhl/ssh.sh !U !@ !P`
Author
Owner

@minhluan259 commented on GitHub (Mar 10, 2020):

Thank you.
The terminal is closing too. Is there any way to keep terminal open?

@minhluan259 commented on GitHub (Mar 10, 2020): Thank you. The terminal is closing too. Is there any way to keep terminal open?
Author
Owner

@zadjii-msft commented on GitHub (Mar 10, 2020):

You could try adding "closeOnExit": "never" to the profile you're launching. That's documented here:

Property Necessity Type Default Description
closeOnExit Optional String graceful Sets how the profile reacts to termination or failure to launch. Possible values: "graceful" (close when exit is typed or the process exits normally), "always" (always close) and "never" (never close). true and false are accepted as synonyms for "graceful" and "never" respectively.
@zadjii-msft commented on GitHub (Mar 10, 2020): You could try adding `"closeOnExit": "never"` to the profile you're launching. That's documented [here](https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md): Property | Necessity | Type | Default | Description -- | -- | -- | -- | -- closeOnExit | Optional | String | graceful | Sets how the profile reacts to termination or failure to launch. Possible values: "graceful" (close when exit is typed or the process exits normally), "always" (always close) and "never" (never close). true and false are accepted as synonyms for "graceful" and "never" respectively.
Author
Owner

@ghost commented on GitHub (Mar 24, 2020):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Mar 24, 2020): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@tihomir-kit commented on GitHub (Jul 4, 2020):

I'm having the same issue, I can't figure out how to run a command upon executing wt. For example, I would expect something as simple as wt dir to run WT and then execute the dir command. I just get this though: "[error 0x80070002 when launching `dir']".

#5528 seems relevant.

@tihomir-kit commented on GitHub (Jul 4, 2020): I'm having the same issue, I can't figure out how to run a command upon executing `wt`. For example, I would expect something as simple as `wt dir` to run WT and then execute the `dir` command. I just get this though: "[error 0x80070002 when launching `dir']". #5528 seems relevant.
Author
Owner

@maicol07 commented on GitHub (Nov 16, 2020):

Same error

@maicol07 commented on GitHub (Nov 16, 2020): Same error
Author
Owner

@zadjii-msft commented on GitHub (Nov 16, 2020):

dir is a "cmd intrinsic" - it's not an executable on its own, rather something built in to cmd itself. For things that are cmd intrinsics, you'll need to period the command with cmd /c , to make the command run inside the cmd.exe process. Ex cmd /c dir should work

@zadjii-msft commented on GitHub (Nov 16, 2020): `dir` is a "cmd intrinsic" - it's not an executable on its own, rather something built in to cmd itself. For things that are cmd intrinsics, you'll need to period the command with `cmd /c `, to make the command run inside the cmd.exe process. Ex `cmd /c dir` should work
Author
Owner

@maicol07 commented on GitHub (Nov 16, 2020):

@zadjii-msft I've tried also to run the ls command but doesn't work

@maicol07 commented on GitHub (Nov 16, 2020): @zadjii-msft I've tried also to run the ls command but doesn't work
Author
Owner

@zadjii-msft commented on GitHub (Nov 16, 2020):

Okay well what's the full commandline you're trying, and what's the path to ls on your machine?

@zadjii-msft commented on GitHub (Nov 16, 2020): Okay well what's the full commandline you're trying, and what's the path to `ls` on your machine?
Author
Owner

@maicol07 commented on GitHub (Nov 16, 2020):

I mean I would like that when the terminal starts, it execute the ls command and shows his output.

So the final result would be:

@maicol07 commented on GitHub (Nov 16, 2020): I mean I would like that when the terminal starts, it execute the ls command and shows his output. So the final result would be: ![](https://user-images.githubusercontent.com/9463142/99261546-27b0e880-281d-11eb-9ead-711e00903b73.png)
Author
Owner

@zadjii-msft commented on GitHub (Nov 16, 2020):

Alright, so, I can only guess that you're using WSL, and you're trying to run ls inside of WSL.

Turns out, this is in general, a hard problem with bash.

While this won't work in the general case, this will work for the simple ls case:

wt wsl bash -c "ls -lA --color & bash"

image

@zadjii-msft commented on GitHub (Nov 16, 2020): Alright, so, I can only guess that you're using WSL, and you're trying to run `ls` inside of WSL. Turns out, this is _in general_, a [hard problem with `bash`](https://stackoverflow.com/questions/7120426/how-to-invoke-bash-run-commands-inside-the-new-shell-and-then-give-control-bac). While this won't work in the general case, this will work for the simple `ls` case: ```cmd wt wsl bash -c "ls -lA --color & bash" ``` ![image](https://user-images.githubusercontent.com/18356694/99262185-44302f00-27e3-11eb-841b-0423c6c41488.png)
Author
Owner

@maicol07 commented on GitHub (Nov 16, 2020):

@zadjii-msft There's only one issue with this: in my real use case, I need to get the output of a command that waits some seconds before outputting. With your solution, it returns control instantly after running the desired command

@maicol07 commented on GitHub (Nov 16, 2020): @zadjii-msft There's only one issue with this: in my real use case, I need to get the output of a command that waits some seconds before outputting. With your solution, it returns control instantly after running the desired command
Author
Owner

@zadjii-msft commented on GitHub (Nov 16, 2020):

Alright well, I'm sure there's other ways of doing this better. I'm not really a bash scripting expert. Maybe replacing the & with a \; (to escape the ;) might work better? I might just be really bad at bash.

The thread I linked on stack overflow has a long list of better ways of running a script than what I've posted. That's just the dead-simple ls case.

@zadjii-msft commented on GitHub (Nov 16, 2020): Alright well, I'm sure there's other ways of doing this better. I'm not really a `bash` scripting expert. Maybe replacing the `&` with a `\;` (to escape the `;`) might work better? I might just be really bad at `bash`. The thread I linked on stack overflow has a long list of better ways of running a script than what I've posted. That's just the dead-simple `ls` case.
Author
Owner

@Ones97 commented on GitHub (Apr 23, 2022):

wt.exe --title "PuTTY" \plink.exe -pw !P -load "WinSCP temporary session" -no-antispoof

@Ones97 commented on GitHub (Apr 23, 2022): wt.exe --title "PuTTY" <path>\plink.exe -pw !P -load "WinSCP temporary session" -no-antispoof
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6802