windowswindows-7windows-7-x64

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


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 Photoshop.

Any ideas?


Solution

  • All you need to do 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.