microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.74k stars 8.33k forks source link

wt support run command in application #4864

Closed minhluan259 closed 4 years ago

minhluan259 commented 4 years ago

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"

zadjii-msft commented 4 years ago

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?

minhluan259 commented 4 years ago

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

zadjii-msft commented 4 years ago

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.

minhluan259 commented 4 years ago

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 4 years ago

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

zadjii-msft commented 4 years ago

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

minhluan259 commented 4 years ago

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

zadjii-msft commented 4 years ago

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.
ghost commented 4 years ago

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.

tihomir-kit commented 4 years ago

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.

maicol07 commented 4 years ago

Same error

zadjii-msft commented 4 years ago

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

maicol07 commented 4 years ago

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

zadjii-msft commented 4 years ago

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

maicol07 commented 4 years ago

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:

zadjii-msft commented 4 years ago

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

maicol07 commented 3 years ago

@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

zadjii-msft commented 3 years ago

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.

Ones97 commented 2 years ago

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