I would like to start Ubuntu WSL [shell: bash] inside Windows Terminal from a batch file and pass a command, which should immediately run after startup.
- When directly starting WSL, I'm able to do this using the
-cargument; e.g. the following opens WSL and establishes an SSH connection with some local port forwardings:bash -c "ssh -L 3306:localhost:3306 -L 5900:localhost:5900 -L 8001:localhost:8001 user@target.com"
How would I achieve this using Windows Terminal?
/etc/rc.localscript,crontab, etc., of which bypasses the Windows side of it altogether? – JW0914 Aug 18 '20 at 14:02wtfrom batch/PowerShell/... is not the issue here but handing it a cmd to execute after startup is. Also I don't want to run my batch file on a scheduled basis but execute it manually, so I don't think the Task Scheduler will help me in any way. Usingrc.localorcrontabalso don't really help me here since I don't want to run my cmd EVERYTIME I start the WSL bash but only when started from my batch file... Thanks for your input! – suamikim Aug 18 '20 at 14:22wtfrom a script, aswtlacks basic terminal emulation functionality (it's still a beta). What I was talking about is issuing the WSL Bash terminal command directly via a Powershell script and is likely the only way to natively do what you want to do. As I previously mentioned, you can do exactly what you're trying to do via ConEmu by adding a Task [a terminal profile] in Settings → Startup → Tasks (you can also specify variables in Settings → Startup → Environment). ConEmu should auto-add the WSL terminal during install/first launch. – JW0914 Aug 18 '20 at 14:42wtstart cmd? So I don't really see how PowerShell gives me more "power" here then a regular bash script? RegardingConEmu: Thanks for the tip, however I'm not looking for an alternative towtATM. – suamikim Aug 18 '20 at 14:50wtis a Terminal Emulator, not a terminal... the terminal is Bash. To make this simpler, simply install ConEmu and you can issue the command as written in your question. (Since WSL'S Bash terminal is now hardcoded into Windows 10 [it's available in the Context Menu], it should be able to be called from a Powershell script, but to keep this simple, simply use ConEmu instead of Windows Terminal, at the very least until it's finalized software with the full functionality of a terminal emulator.) – JW0914 Aug 18 '20 at 14:55