[英]Python script won't run from the context menu
[Submitted to superuser two days ago, but nobody could answer it, so reposting here.] [两天前提交给超级用户,但没人能回答,所以在这里重新发布。]
Working on the basis of this post (and this follow-up post ), I've tried adding a python script (which I've added to the path and so on, so that I can run it from the command line everywhere in the system) to the context menu, like this: 在本文 (以及后续文章 )的基础上,我尝试添加一个python脚本(已将其添加到路径中,依此类推,以便可以从命令行中的任何位置运行它)。系统)到上下文菜单,如下所示:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs]
@="&Get Abstracts"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"
[HKEY_CLASSES_ROOT\Directory\Background\shell\get_abs\command]
@="C:\\cmdtools\\get_abs.py"
However, I get a strange error message when I try to run it. 但是,当我尝试运行它时,收到一条奇怪的错误消息。
To be clear, I have successfully run this script from the command line (using powershell, in case it matters) in the folder in which I'm trying to run it from the context menu. 明确地说,我已经成功地从命令行(在需要的情况下使用powershell)在要从上下文菜单运行该脚本的文件夹中运行了该脚本。
Python scripts aren't natively executable by Windows; Windows无法原生执行Python脚本; it's complaining that you didn't specify an .exe
file. 它抱怨您未指定.exe
文件。 That's easy though, you just specify python.exe
. 不过,这很容易,您只需指定python.exe
。 Follow that up with the path to your script and then a %1
-- this is a placeholder for the path to the clicked file. 接着是脚本的路径,然后是%1
这是单击文件路径的占位符。 To allow your command to work with paths with spaces in them, surround the %1
with quote marks. 要允许您的命令使用路径中带有空格的路径,请在%1
周围加上引号。 Putting it all together, we get: 放在一起,我们得到:
C:\path\to\python.exe C:\path\to\your\script.py "%1"
BTW, a handy utility for managing context menus is Fast Explorer . 顺便说一句, 快速管理器是用于管理上下文菜单的便捷实用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.