开发者

bat script linking to python script

I have a .bat that sets up an environment which allows users to execute several pyth开发者_如何转开发on 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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜