Re: Converting .py files to batch files.

Discussion in 'Python' started by Matias Surdi, Sep 15, 2008.

  1. Matias Surdi

    Matias Surdi Guest

    aditya shukla escribió:
    > How can we convert .py files to batch files? is there any library for this?
    >
    >
    > Aditya
    >
    >
    > ------------------------------------------------------------------------
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list


    Maybe py2exe can help you.
    Matias Surdi, Sep 15, 2008
    #1
    1. Advertising

  2. On Sep 15, 3:04 pm, Matias Surdi <> wrote:
    > aditya shukla escribió:
    >
    > > How can we convert .py files to batch files? is there any library for this?

    >
    > > Aditya

    >
    > > ------------------------------------------------------------------------

    >
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > Maybe py2exe can help you.


    I assume you are on Windows? Let's assume you have a file stuff.py
    that reads:

    import os
    print os.listdir('.') # list current directory, good enough for
    testing...

    Then, insert the following line at the top:

    @setlocal enableextensions & python -x %~f0 %* & goto :EOF

    Now save this file as stuff.cmd somewhere along your PATH. Now calling
    'stuff' should execute your file.
    On Linux, you would instead insert the shebang line that points to
    your python interpreter, such as

    #!/usr/bin/python

    at the top and also set the executable bit, but I suppose if you use
    Linux at all you know that.
    Michael Palmer, Sep 16, 2008
    #2
    1. Advertising

  3. En Mon, 15 Sep 2008 20:36:05 -0300, Michael Palmer <>
    escribió:
    >> aditya shukla escribió:
    >>
    >> > How can we convert .py files to batch files? is there any library for

    >> this?

    >
    > I assume you are on Windows? Let's assume you have a file stuff.py
    > that reads:
    >
    > import os
    > print os.listdir('.') # list current directory, good enough for
    > testing...
    >
    > Then, insert the following line at the top:
    >
    > @setlocal enableextensions & python -x %~f0 %* & goto :EOF
    >
    > Now save this file as stuff.cmd somewhere along your PATH. Now calling
    > 'stuff' should execute your file.


    Cool! I'd enclose the first argument in quotes "%~f0" - in case the path
    contains any whitespace.

    --
    Gabriel Genellina
    Gabriel Genellina, Sep 16, 2008
    #3
  4. Matias Surdi

    r0g Guest

    Michael Palmer wrote:
    > On Sep 15, 3:04 pm, Matias Surdi <> wrote:
    >> aditya shukla escribió:
    >>
    >>> How can we convert .py files to batch files? is there any library for this?
    >>> Aditya
    >>> ------------------------------------------------------------------------

    <snip>> On Linux, you would instead insert the shebang line that points to
    > your python interpreter, such as
    >
    > #!/usr/bin/python
    >
    > at the top and also set the executable bit, but I suppose if you use
    > Linux at all you know that.


    Doh! I'm new to Linux and so I didn't know that, thanks!
    One small snag though, it doesn't work on my system :-(
    I did both steps, the shebang and the execute bit but nada...

    r0g@steppa:~/Desktop/py$ ls
    kickstart.py kickstart.py~ kicktest.py kicktest.py~
    r0g@steppa:~/Desktop/py$ kickstart.py
    bash: kickstart.py: command not found

    Any ideas why this might be? A path thing? I'm on Ubuntu 8.04 / Py2.5

    Thanks,

    Roger.
    r0g, Sep 17, 2008
    #4
  5. Matias Surdi

    r0g Guest

    Grant Edwards wrote:
    > On 2008-09-17, r0g <> wrote:
    >
    >> r0g@steppa:~/Desktop/py$ ls
    >> kickstart.py kickstart.py~ kicktest.py kicktest.py~
    >> r0g@steppa:~/Desktop/py$ kickstart.py
    >> bash: kickstart.py: command not found
    >>
    >> Any ideas why this might be?

    >
    > Yes.
    >
    >> A path thing?

    >
    > Yes.
    >
    > Linux systems generally don't have the current directory in the
    > PATH that's searched for executbles (it's regarded as a rather
    > serious security problem if you do).
    >
    > Try doing this:
    >
    > ./kickstart.py
    >


    Brilliant! :D Thanks v.much for that, turns out the very same thing had
    been driving me nuts a few days earlier when I was trying to run an
    installer I had downloaded, bit of an Izzard Printer moment LOL -
    http://www.youtube.com/watch?v=2wHEqDepAXo

    Thanks again!

    Roger.

    http://www.technicalbloke.com
    http://movingtoubuntu.technicalbloke.co.uk
    r0g, Sep 17, 2008
    #5
    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. =?Utf-8?B?U3JlZWx1?=

    Running batch files using Process class

    =?Utf-8?B?U3JlZWx1?=, Jul 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    426
    Scott Allen
    Jul 28, 2005
  2. Stephen

    Running Batch Files using ASP .NET

    Stephen, Dec 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,548
    Stephen
    Dec 22, 2005
  3. pomegran
    Replies:
    1
    Views:
    363
    Gordon Beaton
    Oct 1, 2003
  4. Replies:
    7
    Views:
    5,728
    Steve W. Jackson
    Apr 12, 2005
  5. Chris Rebert

    Re: Converting .py files to batch files.

    Chris Rebert, Sep 15, 2008, in forum: Python
    Replies:
    0
    Views:
    374
    Chris Rebert
    Sep 15, 2008
Loading...

Share This Page