windows 如何使用指定的程序从命令行打开文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16344709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:28:54  来源:igfitidea点击:

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

windowswindows-7windows-7-x64

提问by csterling

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.

我想从命令行在 Photoshop 中打开 PDF。我现在的问题是打开 PDF 的默认应用程序是 Adob​​e Acrobat。我想知道是否可以传递任何参数来指定打开文件时要使用的程序。

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.

我不想将 PDF 的默认应用程序更改为 Photoshop。

Any ideas?

有任何想法吗?

回答by Adi Inbar

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 Pathenvironment variable, you'll need to provide the full path:

如果包含 photoshop.exe 的目录不在您的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.

这不是命令提示符的功能,而是可执行文件的功能,即必须对 photoshop.exe 进行编程以接受要作为命令行参数打开的文件。幸运的是,正如大多数对文件进行操作的 Windows 应用程序一样。

回答by Seperman

In case you want this to work with relative path in PowerShell, here is the script:

如果您希望在 PowerShell 中使用相对路径,这里是脚本:

function photo
{
   $the_filename=resolve-path $args[0]
   photoshop $the_filename
}

Then you can just type:

然后你可以输入:

cd C:\Users\csterling\Documents
photo mypic.jpg

回答by Andrew Feldman

Unfortunately, the current version of Photoshop doesn't support this operation out of the box. You can open the program: start "path_to_photoshop.exe", but there is no way to pass it a file to open. If you really want to do it, you will need to get something like this: https://www.eulanda.eu/en/access-photoshop-api-via-powershell-script. Sorry, I wish I had a better answer, especially since I wanted to be able to do this for a program I was working on.

不幸的是,当前版本的 Photoshop 不支持这种开箱即用的操作。您可以打开程序:start "path_to_photoshop.exe",但无法将文件传递给它以打开。如果你真的想这样做,你需要得到这样的东西:https://www.eulanda.eu/en/access-photoshop-api-via-powershell-script。抱歉,我希望我有更好的答案,尤其是因为我希望能够为我正在开发的程序执行此操作。