how to get started with wsl code example

Example 1: start wsl with command

Pass commandline to wt:
As shown in Option 1, the commandline option can include further parameters for the target shell, with the following working when called from a batch file:
wt wsl.exe ssh -L 3306:localhost:3306 -L 5900:localhost:5900 -L 8001:localhost:8001 [email protected]
I did not find any official online resources explaining why this works, adjusting the suggestions in this answer, so I'm not sure whether this is supposed to work this way or if it's a hidden/unintentional feature that could break in future versions.

Example 2: start wsl with command

Create a dedicated profile:
The commandline option also accepts arguments, which are directly passed to the shell on startup, allowing the direct usage of wsl.exe with an additional "startup command":
{
  "guid": "{...}",
  "hidden": false,
  "name": "Ubuntu SSH",
  "commandline": "wsl.exe ssh -L 3306:localhost:3306 -L 5900:localhost:5900 -L 8001:localhost:8001 [email protected]",
}
I can now start the shell via a batch file, which runs using the below; however, the downside is the new profile is shown in Windows Terminal's Profile Selection Menu:
wt -p "Ubuntu SSH"

Tags:

Misc Example