Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting startingDirectory on command line for WSL2 Location Windows 11 Ubuntu 24.04 fails #18162

Closed
yorkshire-pudding opened this issue Nov 7, 2024 · 4 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@yorkshire-pudding
Copy link

yorkshire-pudding commented Nov 7, 2024

Windows Terminal version

1.21.2911.0

Windows build number

10.0.22631.4317

Other Software

Ubuntu 24.04.1 LTS inside WSL2 (2.3.24.0)
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)

Steps to reproduce

  1. Create bash script in WSL2 to open a tab at a particular location
#!/bin/bash
# Create tab for Scripts
cmd.exe /c "wt.exe" \
  --window 0 \
  new-tab --title Scripts --suppressApplicationTitle \
  --profile "Ubuntu" \
  --startingDirectory "$HOME/projects/scripts"
  1. Run script

I followed these instructions: https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=linux#target-a-directory
which do not give any insight into WSL2 locations. (Note I prefer to use verbose options in scripts for later readability which is why I have --startingDirectory rather than -d)

I also tried:

  • --startingDirectory "~/projects/scripts"
  • --startingDirectory "/home/user/projects/scripts"
  • --startingDirectory '\\wsl$\Ubuntu\home\user\projects\scripts'
  • --startingDirectory "\\\\wsl.localhost\\Ubuntu\\home\\user\\projects\\scripts" - this without the escaped \ is the location I see in Windows Explorer
  • --startingDirectory "\\wsl.localhost\Ubuntu\home\user\projects\scripts" - this fails with error:
    • [error 2147942667 (0x8007010b) when launching 'ubuntu.exe'] Could not access starting directory C:\wsl.localhost\Ubuntu\home\user\projects\scripts"

Expected Behavior

Tab opens at location with title.

This worked in Windows 10 with Ubuntu 20.04 inside WSL2

Actual Behavior

Tab opens at home location (i.e. ~) with title

@yorkshire-pudding yorkshire-pudding added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Nov 7, 2024
@carlos-zamora
Copy link
Member

Thanks for filing! This bug has actually been reported before (i.e. #15827's comment). It's being tracked in #12961 so we'll mark this as a /dup of #12961. However, as a workaround, you can try changing the commandline to wsl -d Ubuntu-24.04 (or whatever the actual name of the distribution is). That should make startingDirectory work again.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Nov 14, 2024
@yorkshire-pudding
Copy link
Author

@carlos-zamora

However, as a workaround, you can try changing the commandline to wsl -d Ubuntu-24.04 (or whatever the actual name of the distribution is). That should make startingDirectory work again.

Perhaps I'm being thick, but I can't follow which bit of my script I would add that in or swap. It would be wsl -d Ubuntu but I wasn't aware that that can take a command. Please can you provide a bit more guidance?

@DHowett
Copy link
Member

DHowett commented Nov 14, 2024

@yorkshire-pudding Sure!

If you go to the Settings inside Terminal for the Ubuntu 24.04 profile, you can change the "commandline" that that profile executes.

Right now, it should be set to something like ubuntu2404.exe.

Today, our logic that lets you set startingDirectory to a Linux filesystem path only works with wsl.exe (this is a point of contention, and not an easy fix for either us or Canonical). It can't be applied to ubuntu2404.exe.

So if you switch the command line from ubuntu2404.exe to wsl.exe -d DistributionName, it will keep working (and cut out Ubuntu's bespoke launcher) and gain the ability to use Linux paths as a starting directory.

FWIW, though, you will want to confirm the internal name of the distro as seen by WSL by running wsl -l.

@yorkshire-pudding
Copy link
Author

Thanks @DHowett - that makes sense now and my script is now working again.
Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants