How to open a file from the command line with a specified program?

csterling picture csterling · May 2, 2013 · Viewed 94.5k times · Source

I would like to open a PDF in Photoshop from the command line. My current issue right now is that the default application for opening PDFs is Adobe Acrobat. I'm wondering if there is any parameter I can pass to specify which program to use when opening a file.

In other words, I want to emulate the option of "Open-with" when you right-click a file to open it with the non-default application, but from the command line.

I do not want to change the default application for PDFs to be Photoshop.

Any ideas?

Answer

Adi Inbar picture Adi Inbar · May 2, 2013

All you need to is provide the filename as a command line argument:

photoshop <path to file>

(<path to file> needs to be quoted if it contains spaces)

For example:

photoshop "C:\Users\csterling\Documents\some document.pdf"

If the directory containing photoshop.exe isn't in your Path environment variable, you'll need to provide the full path:

"C:\Program Files\Adobe\Photoshop\photoshop" "C:\Users\csterling\Documents\some document.pdf"

This isn't a feature of the command prompt, it's a feature of the executable, i.e. photoshop.exe has to be programmed to accept a file to open as a command line argument. Fortunately, it is, as are the majority of Windows applications that operate on files.