Windows Cmd.exe Window
Duncan Booth
duncan.booth at invalid.invalid
Thu Jul 7 10:35:42 EDT 2005
Giles Brown wrote:
> The special first line is:
>
> @pythoncmd -x "%~f0" %* & exit /b
>
> (In the python.org FAQ for windows it says
> @setlocal enableextensions & python -x %~f0 %* & goto :EOF
> but since I have no idea which is "right" I chose the simpler looking
> one)
>
> This approach does require pythoncmd.exe to by in your %PATH% but I
> think that is reasonable ;)
>
> I am a bit disappointed I couldn't think of a way of deciding if I was
> running a ".cmd" file in sitecustomize.py so that I could just use the
> normal python.exe. Using a renamed interpreter .exe is just a trick
> for detecting when I am running .cmd files, but it means that the
> script won't run on another machine that hasn't had the python.exe
> copied to pythoncmd.exe on it. Which is a shame.
I'm having problems understanding your problem. If the file is a .cmd
file then surely the second line (i.e. the one immediately following the
python -x command) could simply do "import sethook" where sethook would
be a module that sets your excepthook.
Alternatively you could check at any point whether sys.argv[0] ends with
'.cmd' or '.bat' (after lowercasing).
>
> So my question. Is there a better way? I'm not really happy with
> this approach. Should I stop worrying and go and play my new ukulele?
> Answers please.
Go on, upload some ukulele playing somewhere.
BTW, another solution is to push the pause command out to the shell:
-----------------------
@setlocal enableextensions & (python -x %~f0 %* || pause) & goto :EOF
import sys
if len(sys.argv) > 1:
sys.exit("this will pause")
-----------------------
will pause only if the python program terminates with a non-zero exit code.
This means messages from sys.exit will cause a pause as well as exceptions.
More information about the Python-list
mailing list