bat脚本链接到python脚本

发布于 2024-10-15 12:41:10 字数 527 浏览 2 评论 0原文

我有一个 .bat 设置一个环境,允许用户为特定作业执行多个 python 脚本。我的目标是创建脚本的链接。

例如,用户运行 .bat,会弹出一个 cmd 窗口,而不是输入 python theLongestPythonScriptNameInTheWorld.py,而是输入 python go

我的目标平台是Windows XP,所以mklink在这里不起作用。我不想使用 fsutil 硬链接。另外,我只是尝试了 set ok=theLongestPythonScriptNameInTheWorld.py,但我宁愿避免用户必须输入 python %go% (模数,因为如果我被要求输入模数)。我还想避免 WSH,因为我希望它在本机 XP 安装上运行。

除了mklinkfsutilsetWSH之外还有其他解决方案吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可爱暴击 2024-10-22 12:41:10

您的批处理文件可以接受一个参数,并使用该参数来决定要运行哪个 Python 包。

@echo off
REM Set Environment Here
if %1=="GO" python yourLongestScriptNameInTheWorld.py %2 %3 %4 %5
if %1=="STOP" python anotherScript.py %2 %3 %4 %5

因此,如果批处理文件名为 foo.bat,他们可以键入:

foo GO arg1 arg2 arg3

或者,如果您不希望用户将参数传递给 bat 文件(例如,您从图标运行它)快捷方式)您可以使用 CHOICE 命令提示用户从列表中选择 Python 包。

我相信,最终您会意识到您正在使用一种非常蹩脚的脚本语言来运行您最喜欢的脚本语言,并决定使用 Python 而不是 Batch 命令语言来完成所有这些操作。

Your batch file could take a parameter, and use that to decide which Python package to run.

@echo off
REM Set Environment Here
if %1=="GO" python yourLongestScriptNameInTheWorld.py %2 %3 %4 %5
if %1=="STOP" python anotherScript.py %2 %3 %4 %5

So, if the batch file is called foo.bat they could type:

foo GO arg1 arg2 arg3

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.

羁绊已千年 2024-10-22 12:41:10

如果你想输入python go,我能想到的唯一方法是将你的脚本重命名为go

或者,像大多数其他人所做的那样,创建一个名为 go.bat 的脚本,其中包含以下内容:

@echo off
python yourLongestScriptNameInTheWorld.py %*

您可以在此批处理文件中设置环境,然后运行 ​​go [your_args]< /代码>。对于用户来说,打字的次数就更少了。

If you want to type python go, the only way I can think of is to rename your script to go.

Or, like most other people have done, create a script named go.bat, with the following content:

@echo off
python yourLongestScriptNameInTheWorld.py %*

You may set the environment in this batch file, then you run go [your_args]. That's even less typing for the users.

娇俏 2024-10-22 12:41:10

当我为自己做类似的事情时,我只是创建了一些批处理文件。

例如,您可以提供 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 invoke python theLongestPythonScriptNameInTheWorld.py

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文