DEV Community

loading...

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

patarapolw profile image Pacharapol Withayasakpunt ・1 min read

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?

Discussion

pic
Editor guide