windows bat file question

Discussion in 'Python' started by Tom Willis, Mar 1, 2005.

  1. Tom Willis

    Tom Willis Guest

    I'm trying to get pylint running on windows and the bat file for it
    seems a little screwy. I'm hoping someone may have figured this out
    already.

    rem = """-*-Python-*- script
    @echo off
    rem -------------------- DOS section --------------------
    rem You could set PYTHONPATH or TK environment variables here
    python %*
    goto exit

    """
    # -------------------- Python section --------------------
    import sys
    from logilab.pylint import lint
    lint.Run(sys.argv[1:])


    DosExitLabel = """
    :exit
    rem """

    All I get is the python prompt, the lines starting at import sys don't
    run. If I throw the lines in a python script, I run into path issues.

    The overall effect I'm trying to achieve is....

    c:\Projects\myproject\pylint mymodule.py



    Any ideas?

    --
    Thomas G. Willis
    http://paperbackmusic.net
     
    Tom Willis, Mar 1, 2005
    #1
    1. Advertising

  2. Tom Willis

    Peter Hansen Guest

    Tom Willis wrote:
    > I'm trying to get pylint running on windows and the bat file for it
    > seems a little screwy. I'm hoping someone may have figured this out
    > already.
    > ...
    > All I get is the python prompt, the lines starting at import sys don't
    > run. If I throw the lines in a python script, I run into path issues.


    What exact command are you typing to try to run it? Where is
    the script relative to the current directory? (Best is to
    cut and paste a copy of the actual command line and result
    that you have in your console.)

    On the topic of the "path issues" in the other case, what do you
    mean by path issues? DOS path issues? sys.path issues? Something
    else? What issues exactly...

    -Peter
     
    Peter Hansen, Mar 1, 2005
    #2
    1. Advertising

  3. Tom Willis

    Tom Willis Guest

    On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <> wrote:
    > Tom Willis wrote:
    > > I'm trying to get pylint running on windows and the bat file for it
    > > seems a little screwy. I'm hoping someone may have figured this out
    > > already.
    > > ...
    > > All I get is the python prompt, the lines starting at import sys don't
    > > run. If I throw the lines in a python script, I run into path issues.

    >
    > What exact command are you typing to try to run it? Where is
    > the script relative to the current directory? (Best is to
    > cut and paste a copy of the actual command line and result
    > that you have in your console.)
    >
    > On the topic of the "path issues" in the other case, what do you
    > mean by path issues? DOS path issues? sys.path issues? Something
    > else? What issues exactly...
    >
    > -Peter
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    I figured it out. I just took the embedded python code that was in the
    batch file distributed with it and put it in it's own module.

    Really my question was how would this ever work? It seems to me to be
    a little screwy, but it would be handy to know if this was some sort
    of convention that I could take advantage of if I ever write something
    substantial that would need to run on windoze.


    REM---bat file---
    rem = """-*-Python-*- script
    @echo off
    rem -------------------- DOS section --------------------
    rem You could set PYTHONPATH or TK environment variables here
    python %*
    goto exit

    """
    # -------------------- Python section --------------------
    print "hello from python"

    DosExitLabel = """
    :exit
    rem """
    REM---end of bat file---

    I'm wondering if this took advantage of some flaw in batch file
    processing that can no longer be used because of some security hole
    that got plugged or something.




    --
    Thomas G. Willis
    http://paperbackmusic.net
     
    Tom Willis, Mar 1, 2005
    #3
  4. Tom Willis

    Steve Holden Guest

    Tom Willis wrote:
    > On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <> wrote:
    >
    >>Tom Willis wrote:
    >>
    >>>I'm trying to get pylint running on windows and the bat file for it
    >>>seems a little screwy. I'm hoping someone may have figured this out
    >>>already.
    >>>...
    >>>All I get is the python prompt, the lines starting at import sys don't
    >>>run. If I throw the lines in a python script, I run into path issues.

    >>
    >>What exact command are you typing to try to run it? Where is
    >>the script relative to the current directory? (Best is to
    >>cut and paste a copy of the actual command line and result
    >>that you have in your console.)
    >>
    >>On the topic of the "path issues" in the other case, what do you
    >>mean by path issues? DOS path issues? sys.path issues? Something
    >>else? What issues exactly...
    >>
    >>-Peter
    >>--
    >>http://mail.python.org/mailman/listinfo/python-list
    >>

    >
    >
    > I figured it out. I just took the embedded python code that was in the
    > batch file distributed with it and put it in it's own module.
    >
    > Really my question was how would this ever work? It seems to me to be
    > a little screwy, but it would be handy to know if this was some sort
    > of convention that I could take advantage of if I ever write something
    > substantial that would need to run on windoze.
    >
    >
    > REM---bat file---
    > rem = """-*-Python-*- script
    > @echo off
    > rem -------------------- DOS section --------------------
    > rem You could set PYTHONPATH or TK environment variables here
    > python %*
    > goto exit
    >
    > """
    > # -------------------- Python section --------------------
    > print "hello from python"
    >
    > DosExitLabel = """
    > :exit
    > rem """
    > REM---end of bat file---
    >
    > I'm wondering if this took advantage of some flaw in batch file
    > processing that can no longer be used because of some security hole
    > that got plugged or something.
    >
    >
    >
    >

    It was clearly originally intended to be run as "name" and then pipe the
    batch file into the Python interpreter, but as to how the hell it was
    actually supposed to work, your guess is as good as mine.

    regards
    Steve


    --
    Meet the Python developers and your c.l.py favorites March 23-25
    Come to PyCon DC 2005 http://www.pycon.org/
    Steve Holden http://www.holdenweb.com/
     
    Steve Holden, Mar 1, 2005
    #4
  5. Tom Willis

    Peter Hansen Guest

    Tom Willis wrote:
    > I figured it out. I just took the embedded python code that was in the
    > batch file distributed with it and put it in it's own module.
    >
    > Really my question was how would this ever work? It seems to me to be
    > a little screwy, but it would be handy to know if this was some sort
    > of convention that I could take advantage of if I ever write something
    > substantial that would need to run on windoze.


    It looks like it might have been an untested version of something
    that should have been using "python %0 %*" at that line instead
    of just "python %*".

    Under Windows XP (and probably NT, but not 98) the %* means
    "all arguments", but doesn't appear (in testing just now on
    my own machine) to include the name of the batch file itself.

    On the other hand, %0 does include the name of the batch file,
    but unfortunately it's actually just the part that you typed,
    as in "blah" instead of "blah.bat" if you executed the file
    by typing just "blah" instead of "blah.bat".

    All things considered, it does look like it could never have
    worked properly, but Windows is freakish enough that there
    might well be some sequence of events and set of conditions
    under which it might actually work as intended...

    Of course, if you're on XP where you could hope that the
    %* magic could work at all, you can also just modify the
    contents of the environment variable PATHEXT to include .py,
    rename the script to .py and strip out all that crappy
    BAT stuff, and run it as intended with (almost) no
    complications.

    -Peter
     
    Peter Hansen, Mar 1, 2005
    #5
  6. Tom Willis

    Tim Roberts Guest

    Tom Willis <> wrote:

    >I'm trying to get pylint running on windows and the bat file for it
    >seems a little screwy. I'm hoping someone may have figured this out
    >already.
    >
    >rem = """-*-Python-*- script
    >@echo off
    >rem -------------------- DOS section --------------------
    >rem You could set PYTHONPATH or TK environment variables here
    >python %*


    This should make it work:
    python %0.bat %*

    >goto exit
    >
    >"""
    ># -------------------- Python section --------------------
    >import sys
    >from logilab.pylint import lint
    >lint.Run(sys.argv[1:])
    >
    >
    >DosExitLabel = """
    >:exit
    >rem """

    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Mar 3, 2005
    #6
  7. Tom Willis

    Peter Hansen Guest

    Tim Roberts wrote:
    > Tom Willis <> wrote:
    >>rem = """-*-Python-*- script
    >>@echo off
    >>rem -------------------- DOS section --------------------
    >>rem You could set PYTHONPATH or TK environment variables here
    >>python %*

    >
    > This should make it work:
    > python %0.bat %*


    Only, among other issues, if you type the full path to the
    batch file, or if it's in the current directory. This
    approach fails if you put the batch file in a directory
    somewhere along your path.

    There are only a couple of useful ways to do this sort of
    thing under Windows operating systems, and the easiest by
    far is to abandon any support for Windows 98 and just use
    the PATHEXT support in Windows NT/XP and friends.

    -Peter
     
    Peter Hansen, Mar 3, 2005
    #7
  8. Tom Willis

    Duncan Booth Guest

    Peter Hansen wrote:

    >> This should make it work:
    >> python %0.bat %*

    >
    > Only, among other issues, if you type the full path to the
    > batch file, or if it's in the current directory. This
    > approach fails if you put the batch file in a directory
    > somewhere along your path.


    The simplest fix, assuming we aren't talking Win9x is probably:

    python "%~f0" %*

    > There are only a couple of useful ways to do this sort of
    > thing under Windows operating systems, and the easiest by
    > far is to abandon any support for Windows 98 and just use
    > the PATHEXT support in Windows NT/XP and friends.


    And if you can't be bothered with PATHEXT then just make sure to always
    type the .py in as part of the command line:

    C:\>myscript.py

    will run a Python script without any messing. If the script is in the
    current directory then you can use tab completion to avoid typing the whole
    name anyway.
     
    Duncan Booth, Mar 3, 2005
    #8
  9. Tom Willis

    Peter Hansen Guest

    Duncan Booth wrote:
    > Peter Hansen wrote:
    >>>This should make it work:
    >>> python %0.bat %*

    >>
    >>Only, among other issues, if you type the full path to the
    >>batch file, or if it's in the current directory. This
    >>approach fails if you put the batch file in a directory
    >>somewhere along your path.

    >
    >
    > The simplest fix, assuming we aren't talking Win9x is probably:
    >
    > python "%~f0" %*


    Wow. The myriad things that get slipped into these little
    operating systems while you aren't looking. Windows XP's command
    shell begins to border on being marginally acceptable for some
    limited types of scripting.

    Unfortunately, Google makes it hard to search for such things,
    but after a while I was able to dig up this master reference:

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx

    Thanks, Duncan!

    -Peter
     
    Peter Hansen, Mar 3, 2005
    #9
  10. Tom Willis

    Duncan Booth Guest

    Peter Hansen wrote:

    > Unfortunately, Google makes it hard to search for such things,
    > but after a while I was able to dig up this master reference:
    >
    > http://www.microsoft.com/resources/documentation/windows/xp/all/proddoc
    > s/en-us/percent.mspx


    You will find even more information if you try 'set /?' or 'for /?' at a
    command prompt. As you say, you can now do quite complicated scripting in
    command files but it needs masochism second only to Perl programming.
     
    Duncan Booth, Mar 4, 2005
    #10
  11. Tom Willis

    Alan Gauld Guest

    On 4 Mar 2005 10:18:08 GMT, Duncan Booth
    <> wrote:
    > You will find even more information if you try 'set /?' or 'for /?' at a
    > command prompt. As you say, you can now do quite complicated scripting in
    > command files but it needs masochism second only to Perl programming.


    And using WSH is so much easier, even JavaScript and VBScript are
    pleasant compared to CMD language... And of course Python can be
    used if appropriately installed, but then you'd probably just use
    Python!

    Alan G.
    Author of the Learn to Program website
    http://www.freenetpages.co.uk/hp/alan.gauld
     
    Alan Gauld, Mar 5, 2005
    #11
  12. Tom Willis

    Peter Hansen Guest

    Duncan Booth wrote:
    > Peter Hansen wrote:
    >>Unfortunately, Google makes it hard to search for such things,
    >>but after a while I was able to dig up this master reference:
    >>
    >>http://www.microsoft.com/resources/documentation/windows/xp/all/proddoc
    >>s/en-us/percent.mspx

    >
    > You will find even more information if you try 'set /?' or 'for /?' at a
    > command prompt. As you say, you can now do quite complicated scripting in
    > command files but it needs masochism second only to Perl programming.


    As my grandmother used to say when she had made a particularly
    bad shot playing Crokinole, "Gah!"
     
    Peter Hansen, Mar 5, 2005
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grant Merwitz
    Replies:
    3
    Views:
    9,076
    Grant Merwitz
    Sep 15, 2005
  2. Joe
    Replies:
    1
    Views:
    369
    Victor Bazarov
    May 22, 2007
  3. GP
    Replies:
    3
    Views:
    212
  4. John Reed
    Replies:
    1
    Views:
    125
    Andreas Schwarz
    Mar 7, 2004
  5. Eric Hodel
    Replies:
    4
    Views:
    130
    Wilson Bilkovich
    Dec 26, 2006
Loading...

Share This Page