<!--
  canonical-url: https://www.avonture.be/blog/wsl-powershell
  published:     2023-12-27
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Starting the default associated Windows program on WSL

> Learn the simple command to open files like PDFs and HTML from your WSL Linux console using their default Windows application - powershell.exe.

---
![Starting the default associated Windows program on WSL](/img/v2/wsl.webp)

**TL;DR**

This article shares a quick WSL trick: running `powershell.exe <filename>` (e.g. `powershell.exe guide.pdf`) from the Linux console opens that file with its default Windows application, without needing to browse to it in Windows Explorer first. `xdg-open` is mentioned as an alternative for opening the default browser.

Very often, I'm in my Linux console and I'd like to open a pdf file that I've just generated or, more simply, to open an html file. But how can I do this?

Without knowing the tip that is the subject of this article, at the moment I launch [Windows Explorer](/blog/wsl-windows-explorer) from my console, I then get the well-known file explorer interface and there I double-click on the file I want to open and leave it to Windows, which knows which program to launch to open this or that extension.

In fact, it's much simpler...

The tip: start `powershell.exe` followed by the filename to open like `powershell.exe guide.pdf` or `powershell.exe index.html`.

*A typical use case: you've just generated a PDF with [Quarto in Docker](/blog/docker-quarto) and want to check the result without leaving your console.*

> **Not available in Bash:**
>
> `powershell.exe` only works in the console. You can't use it in a Bash script (`.sh`), it won't be recognized there.

> **`xdg-open`:**
>
> You can also use `xdg-open` to start your default browser so `xdg-open index.html` will open the file in your Windows browser.

If you get the error below, you'll find a solution in the article [Windows Explorer](/blog/wsl-windows-explorer#wsl-localhost-is-not-accessible)

```bash
Start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ Start "readme.html"
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
```
