windows bat file question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Willis

    windows bat file question

    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.ar gv[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\myp roject\pylint mymodule.py



    Any ideas?

    --
    Thomas G. Willis

  • Peter Hansen

    #2
    Re: windows bat file question

    Tom Willis wrote:[color=blue]
    > 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.[/color]

    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

    Comment

    • Tom Willis

      #3
      Re: windows bat file question

      On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <peter@engcorp. com> wrote:[color=blue]
      > Tom Willis wrote:[color=green]
      > > 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.[/color]
      >
      > 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
      >[/color]

      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

      Comment

      • Steve Holden

        #4
        Re: windows bat file question

        Tom Willis wrote:[color=blue]
        > On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <peter@engcorp. com> wrote:
        >[color=green]
        >>Tom Willis wrote:
        >>[color=darkred]
        >>>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.[/color]
        >>
        >>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
        >>[/color]
        >
        >
        > 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.
        >
        >
        >
        >[/color]
        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/

        Comment

        • Peter Hansen

          #5
          Re: windows bat file question

          Tom Willis wrote:[color=blue]
          > 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.[/color]

          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

          Comment

          • Tim Roberts

            #6
            Re: windows bat file question

            Tom Willis <tom.willis@gma il.com> wrote:
            [color=blue]
            >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 %*[/color]

            This should make it work:
            python %0.bat %*
            [color=blue]
            >goto exit
            >
            >"""
            ># -------------------- Python section --------------------
            >import sys
            >from logilab.pylint import lint
            >lint.Run(sys.a rgv[1:])
            >
            >
            >DosExitLabel = """
            >:exit
            >rem """[/color]
            --
            - Tim Roberts, timr@probo.com
            Providenza & Boekelheide, Inc.

            Comment

            • Peter Hansen

              #7
              Re: windows bat file question

              Tim Roberts wrote:[color=blue]
              > Tom Willis <tom.willis@gma il.com> wrote:[color=green]
              >>rem = """-*-Python-*- script
              >>@echo off
              >>rem -------------------- DOS section --------------------
              >>rem You could set PYTHONPATH or TK environment variables here
              >>python %*[/color]
              >
              > This should make it work:
              > python %0.bat %*[/color]

              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

              Comment

              • Duncan Booth

                #8
                Re: windows bat file question

                Peter Hansen wrote:
                [color=blue][color=green]
                >> This should make it work:
                >> python %0.bat %*[/color]
                >
                > 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.[/color]

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

                python "%~f0" %*
                [color=blue]
                > 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.[/color]

                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.

                Comment

                • Peter Hansen

                  #9
                  Re: windows bat file question

                  Duncan Booth wrote:[color=blue]
                  > Peter Hansen wrote:[color=green][color=darkred]
                  >>>This should make it work:
                  >>> python %0.bat %*[/color]
                  >>
                  >>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.[/color]
                  >
                  >
                  > The simplest fix, assuming we aren't talking Win9x is probably:
                  >
                  > python "%~f0" %*[/color]

                  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:



                  Thanks, Duncan!

                  -Peter

                  Comment

                  • Duncan Booth

                    #10
                    Re: windows bat file question

                    Peter Hansen wrote:
                    [color=blue]
                    > 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/d...xp/all/proddoc
                    > s/en-us/percent.mspx[/color]

                    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.

                    Comment

                    • Alan Gauld

                      #11
                      Re: windows bat file question

                      On 4 Mar 2005 10:18:08 GMT, Duncan Booth
                      <duncan.booth@i nvalid.invalid> wrote:[color=blue]
                      > 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.[/color]

                      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

                      Comment

                      • Peter Hansen

                        #12
                        Re: windows bat file question

                        Duncan Booth wrote:[color=blue]
                        > Peter Hansen wrote:[color=green]
                        >>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/d...xp/all/proddoc
                        >>s/en-us/percent.mspx[/color]
                        >
                        > 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.[/color]

                        As my grandmother used to say when she had made a particularly
                        bad shot playing Crokinole, "Gah!"

                        Comment

                        Working...