Opening Windows Files from Command, Power, and WSL Shells

This blog post explains how you can open Windows files from the command line by specifying only the name of the file. You can open the file by name from a Windows command shell or PowerShell or you can invoke cmd.exe to open the file from a Windows Subsystem for Linux (WSL) shell.

In a command shell, you can simply specify the name of the file. Windows opens the application associated with the extension using something similar to the start command.

c:\temp\imagefile.png
cd temp
imagefile.png
start imagefile.png
Windows Command Shell

PowerShell seems to require that you specify the path, likely because it does not recognize the filename extension as a command.

cd \temp
imagefile.png
./imagefile.png
PowerShell

WSL seems to make all files on Windows file systems executable, but does not know how to “execute” images. You can pass the file to cmd.exe /c, in which case you likely want to append the command with an ampersand (&) so that you can continue using the shell while the launched application runs.

ls -ltra imagefile.png
file imagefile.png
cmd.exe /c imagefile.png &
./imagefile.png
Windows Subsystem for Linux

Note: possibly coincidentally, brush.exe, which I had been using for storing screen captures, crashed shortly after this last command.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: