DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

2 1

Accessing WSL to-and-from Windows (I still have problems with "PORT" generated in Windows, accessing inside WSL)

Paths and restrictions

Path-wise is the easiest one.

  • Accessing Windows from WSL is always?? possible via
'/mnt/' + windowsPath
  .replace(/^(\S+):/, (_, p: string) => p.toLocaleLowerCase())
  .replace(/\\/g, '/')
Enter fullscreen mode Exit fullscreen mode
  • Accession WSL from Windows is possible via
'\\\\wsl$\\' + osName + wslPath.replace(/\//g, '\\')
Enter fullscreen mode Exit fullscreen mode

Now, I have qualms about forward slashes in Windows paths (seems not the be possible at all); vs backward slashes in Linux paths (seems to be possible, via \\).

Accessing environmental variables (beyond PATH)

This seems to be possible via either

spawnSync('wsl', ['echo', ENVVAR])
Enter fullscreen mode Exit fullscreen mode

and

spawnSync('cmd.exe', ['/c', 'echo', ENVVAR])
Enter fullscreen mode Exit fullscreen mode

Accessing ports

This is where I stumbled. For Windows' Edge browser accessing WSL, it seems to use PORT + 1; but I cannot access Windows spawning ports from WSL (trying with Ankiconnect).

Not sure how does it compare with Docker container vs Host?

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay