Using command line args on Windows

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

    #1

    Using command line args on Windows

    Hello-

    I'm stuck on a Windows machine today and would love to fully play with
    and test a simple python script. I want to be able to type "python
    myscript myarg" somewhere. Is there anything out there to help me? My
    main concern is playing with the myarg in the sys.argv list. I've been
    mucking around with IDLE without much success.

  • Larry Bates

    #2
    Re: Using command line args on Windows

    1) Start a command prompt window
    (Start-Programs-Accessories-Command Prompt)
    2) Change to directory where the python program is stored
    (cd \<path-where-script-stored>)
    3) Type python myscript.py myarg

    -Larry Bates


    k8 wrote:[color=blue]
    > Hello-
    >
    > I'm stuck on a Windows machine today and would love to fully play with
    > and test a simple python script. I want to be able to type "python
    > myscript myarg" somewhere. Is there anything out there to help me? My
    > main concern is playing with the myarg in the sys.argv list. I've been
    > mucking around with IDLE without much success.
    >[/color]

    Comment

    • Diez B. Roggisch

      #3
      Re: Using command line args on Windows

      k8 wrote:[color=blue]
      > Hello-
      >
      > I'm stuck on a Windows machine today and would love to fully play with
      > and test a simple python script. I want to be able to type "python
      > myscript myarg" somewhere. Is there anything out there to help me? My
      > main concern is playing with the myarg in the sys.argv list. I've been
      > mucking around with IDLE without much success.[/color]

      Install cygwin. Don't confuse the cygwin python version with your
      separately installed one, or don't install python via cygwin.

      Regards,

      Diez

      Comment

      • k8

        #4
        Re: Using command line args on Windows

        Thank you thank you thank you- The windows command line sol worked.

        -k8

        Comment

        • Diez B. Roggisch

          #5
          Re: Using command line args on Windows

          k8 wrote:[color=blue]
          > Thank you thank you thank you- The windows command line sol worked.[/color]

          It sure does. But it sucks.. bad tab-completion, few tools, short
          history, limited command-line-editing and so on. But if you want it the
          hard way, it's your choice :)

          Diez

          Comment

          • Fredrik Lundh

            #6
            Re: Using command line args on Windows

            "k8" wrote:
            [color=blue]
            > I'm stuck on a Windows machine today and would love to fully play with
            > and test a simple python script. I want to be able to type "python
            > myscript myarg" somewhere. Is there anything out there to help me?[/color]

            footnote: if you'd prefer to type "myscript myarg" instead, you might want
            to check out this tool:



            </F>



            Comment

            • Duncan Booth

              #7
              Re: Using command line args on Windows

              Fredrik Lundh wrote:
              [color=blue][color=green]
              >> I'm stuck on a Windows machine today and would love to fully play
              >> with and test a simple python script. I want to be able to type
              >> "python myscript myarg" somewhere. Is there anything out there to
              >> help me?[/color]
              >
              > footnote: if you'd prefer to type "myscript myarg" instead, you might
              > want to check out this tool:
              >
              > http://effbot.org/zone/exemaker.htm[/color]

              or even just do:

              SET PATHEXT=.py;%PA THEXT%

              and then "myscript myarg" will work for all scripts on your path without
              compiling (if you don't set PATHEXT then "myscript.p y myarg" will still
              work, and tab completion means you don't generally need to type the .py for
              scripts in the current directory).

              Comment

              • Tim Roberts

                #8
                Re: Using command line args on Windows

                Duncan Booth <duncan.booth@i nvalid.invalid> wrote:
                [color=blue]
                >Fredrik Lundh wrote:
                >[color=green]
                >> footnote: if you'd prefer to type "myscript myarg" instead, you might
                >> want to check out this tool:
                >>
                >> http://effbot.org/zone/exemaker.htm[/color]
                >
                >or even just do:
                >
                > SET PATHEXT=.py;%PA THEXT%
                >
                >and then "myscript myarg" will work for all scripts on your path without
                >compiling (if you don't set PATHEXT then "myscript.p y myarg" will still
                >work, and tab completion means you don't generally need to type the .py for
                >scripts in the current directory).[/color]

                The downside to this is that there is a bug in the NT/2K/XP command
                interpreter which will prevent redirecting from stdin in that case. That
                is:

                C:\Tmp>type x.py
                import sys
                print sys.stdin.readl ine()

                C:\Tmp>echo 123 | python x.py
                123

                C:\Tmp>echo 123 | x.py
                The process tried to write to a nonexistent pipe.

                C:\Tmp>python x.py < x.py
                import sys

                C:\Tmp>x.py < x.py

                C:\Tmp>
                --
                - Tim Roberts, timr@probo.com
                Providenza & Boekelheide, Inc.

                Comment

                Working...