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?

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more