bat脚本链接到python脚本
我有一个 .bat 设置一个环境,允许用户为特定作业执行多个 python 脚本。我的目标是创建脚本的链接。
例如,用户运行 .bat,会弹出一个 cmd 窗口,而不是输入 python theLongestPythonScriptNameInTheWorld.py
,而是输入 python go
。
我的目标平台是Windows XP,所以mklink
在这里不起作用。我不想使用 fsutil 硬链接
。另外,我只是尝试了 set ok=theLongestPythonScriptNameInTheWorld.py
,但我宁愿避免用户必须输入 python %go%
(模数,因为如果我被要求输入模数)。我还想避免 WSH,因为我希望它在本机 XP 安装上运行。
除了mklink
、fsutil
、set
和WSH
之外还有其他解决方案吗?
I have a .bat that sets up an environment which allows users to execute several python scripts for specific jobs. My goal is to create links to the scripts.
For example, the user runs the .bat, a cmd window pops up, and instead of typing python theLongestPythonScriptNameInTheWorld.py
he types python go
.
My target platform is windows XP, so mklink
wont work here. I don't want to use fsutil hardlink
. Also, I simply tried set ok=theLongestPythonScriptNameInTheWorld.py
, but id rather avoid the user having to type python %go%
(the modulos, since it would piss me off if i was required to type modulos). I also want to avoid WSH because I want this to run on native XP installs.
Are there any other solutions besides mklink
, fsutil
, set
, and WSH
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的批处理文件可以接受一个参数,并使用该参数来决定要运行哪个 Python 包。
因此,如果批处理文件名为
foo.bat
,他们可以键入:或者,如果您不希望用户将参数传递给 bat 文件(例如,您从图标运行它)快捷方式)您可以使用 CHOICE 命令提示用户从列表中选择 Python 包。
我相信,最终您会意识到您正在使用一种非常蹩脚的脚本语言来运行您最喜欢的脚本语言,并决定使用 Python 而不是 Batch 命令语言来完成所有这些操作。
Your batch file could take a parameter, and use that to decide which Python package to run.
So, if the batch file is called
foo.bat
they could type:Alternatively, if you don't want the user to pass the parameter to the bat file (say, you are running it from an icon shortcut) you could prompt the user to pick the Python package from a list, with the CHOICE command.
I believe that, eventually, you will realise you are using a pretty crappy scripting language in order to run your favourite scripting language, and decide to do all of this IN Python rather than the Batch command language.
如果你想输入
python go
,我能想到的唯一方法是将你的脚本重命名为go
。或者,像大多数其他人所做的那样,创建一个名为
go.bat
的脚本,其中包含以下内容:您可以在此批处理文件中设置环境,然后运行
go [your_args]< /代码>。对于用户来说,打字的次数就更少了。
If you want to type
python go
, the only way I can think of is to rename your script togo
.Or, like most other people have done, create a script named
go.bat
, with the following content:You may set the environment in this batch file, then you run
go [your_args]
. That's even less typing for the users.当我为自己做类似的事情时,我只是创建了一些批处理文件。
例如,您可以提供 py_go.bat 来调用 python theLongestPythonScriptNameInTheWorld.py
When doing something similar for myself, I just created a few more batch files.
For example, you could provide a
py_go.bat
to invokepython theLongestPythonScriptNameInTheWorld.py