是否有可能推出从一个批处理文件的文件的默认编辑器? [英] Is it possible to launch a file's default editor from a batch file?
问题描述
我们可以使用 PATHEXT
的组合和Windows文件关联做的命令提示符中右键点击一个文件相当于<强>浏览器并点击打开,例如:
We can use a combination of PATHEXT
and the Windows file associations to do the Command Prompt equivalent of right-clicking a file in Explorer and clicking Open, e.g.:
C:\code\python> echo print "Hello, StackOverflow!" >hello.py
C:\code\python> hello
Hello, StackOverflow!
同样,我可以利用这个键入推出的的Photoshop
C:\art\source> StackOverflowLogo.PDF
的实际问题:
我需要的命令提示符相当于右键单击资源管理器中的文件并选择修改代替。
使用我打招呼(的.py)以上,这可能会带来高达Python中的待机编辑。不过,我需要使用的文件类型的操作系统级协会的通用解决方案。我不能假设的。
With my hello(.py) above, that would likely bring up Python's Idle editor. However, I need a universal solution that uses the OS-level association for the file type. I can't assume it.
的想什么,我做的是这个假设的EDIT.BAT文件,会做什么,但推出针对所给的文件编辑器最简单的例子:
The simplest possible example of what I'd like to do would be this hypothetical EDIT.BAT file, which would do nothing but launch the editor for the given filename:
@InsertMagic /Here %1
谢谢! (我希望)。
Thanks! (I hope.)
亚历克斯·K.表明PowerShell中,这当然是一个很好的解决方案。所以上面写我的EDIT.BAT,我可以这样做:
Alex K. suggests Powershell, which is of course a great solution. So to write my EDIT.BAT above, I could do this:
@powershell -command "start -verb edit '%1'"
(这是稍微幼稚,既然有潜在的报价问题,但你的想法。)
(That's slightly naïve, since there are potential quoting issues, but you get the idea.)
为迅速回答干杯。 :)
Cheers for the speedy answer. :)
推荐答案
右键菜单中的这些项目被称为的壳牌动词的,它们可以通过名称调用一个目标文件,但不与任何直接的批处理或Windows命令。
Those items on the right-click menu are called Shell Verbs, they can be invoked by name for a target file but not with any direct batch or windows command.
Win7的/ 2k8r2向上,你可以使用PowerShell从您的批处理文件中做到这一点:
Win7/2k8r2 upwards you can use PowerShell to do it from your batch file:
powershell -command "start -verb edit 'C:\art\source\StackOverflowLogo.PDF'"
这篇关于是否有可能推出从一个批处理文件的文件的默认编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!