Passing arguments to a command line from a python script

Discussion in 'Python' started by =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 19, 2007.

  1. Please forgive me if what I'm asking is non sense...

    I created a little program to authomate the creation of the "setup.py"
    script for py2exe.
    It simply prompts for the main executable script name and then creates
    setup.py, as follows:

    # this is "makesetup.py"

    nombre = raw_input('File name?: ')

    f = open('setup.py', 'w')

    f.write('''
    from distutils.core import setup
    import py2exe

    setup( name = "%s",
    windows = ["%s.pyw"],
    data_files = [ (".", ["%s.rsrc.py"]) ]
    )
    ''' %(nombre, nombre, nombre))

    f.close()

    # end of script

    What I want now is execute the script I just created.
    As far as I know, the only way to execute the script is from a command
    line and typing "setup.py py2exe".

    Can I do this authomatically right from my program?
    If so, how?

    Any hint would be highly appreciated...
    regards,
    Luis
     
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 19, 2007
    #1
    1. Advertising

  2. En Mon, 19 Mar 2007 20:46:56 -0300, Luis M. González <>
    escribió:

    > What I want now is execute the script I just created.
    > As far as I know, the only way to execute the script is from a command
    > line and typing "setup.py py2exe".


    A few ways:
    - os.system("commandline"). Simplest way, but you don't have much control,
    and it blocks until the process finishes.
    - os.popen[234]? or the functions in the popen2 module
    - the subprocess module - the most complete way, but simple enough for
    most cases.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 20, 2007
    #2
    1. Advertising

  3. On Mar 19, 9:25 pm, "Gabriel Genellina" <>
    wrote:
    > En Mon, 19 Mar 2007 20:46:56 -0300, Luis M. González <>
    > escribió:
    >
    > > What I want now is execute the script I just created.
    > > As far as I know, the only way to execute the script is from a command
    > > line and typing "setup.py py2exe".

    >
    > A few ways:
    > - os.system("commandline"). Simplest way, but you don't have much control,
    > and it blocks until the process finishes.
    > - os.popen[234]? or the functions in the popen2 module
    > - the subprocess module - the most complete way, but simple enough for
    > most cases.
    >
    > --
    > Gabriel Genellina




    I'm sorry, but still I can't figure out this...
    Would you please show me a sample usage of os.system or os.popen for
    passing arguments to the command line?
    In this case, I should pass to the command line "setuppy py2exe".

    Thanks!
    Luis
     
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 20, 2007
    #3
  4. =?iso-8859-1?q?Luis_M._Gonz=E1lez?=

    zacherates Guest

    On Mar 19, 9:42 pm, "Luis M. González" <> wrote:
    > On Mar 19, 9:25 pm, "Gabriel Genellina" <>
    > wrote:
    >
    >
    >
    > > En Mon, 19 Mar 2007 20:46:56 -0300, Luis M. González <>
    > > escribió:

    >
    > > > What I want now is execute the script I just created.
    > > > As far as I know, the only way to execute the script is from a command
    > > > line and typing "setup.py py2exe".

    >
    > > A few ways:
    > > - os.system("commandline"). Simplest way, but you don't have much control,
    > > and it blocks until the process finishes.
    > > - os.popen[234]? or the functions in the popen2 module
    > > - the subprocess module - the most complete way, but simple enough for
    > > most cases.

    >
    > > --
    > > Gabriel Genellina

    >
    > I'm sorry, but still I can't figure out this...
    > Would you please show me a sample usage of os.system or os.popen for
    > passing arguments to the command line?
    > In this case, I should pass to the command line "setuppy py2exe".
    >
    > Thanks!
    > Luis


    aaron@athena:~$ python
    Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
    [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> rt = os.system("ls")

    apps Firefox_wallpaper.png s2 tux_sshot_0.ppm
    xorg.conf.diff
    Desktop media s3 work
    downloads permutation.py squeak workspace
    Examples permutation.pyc trackers xorg.conf.aiglx
    >>> rt

    0
    >>>


    This implies that `os.system("setuppy py2exe")` should do what you
    want.
     
    zacherates, Mar 20, 2007
    #4
  5. On Mar 19, 10:49 pm, "zacherates" <> wrote:
    > On Mar 19, 9:42 pm, "Luis M. González" <> wrote:
    >
    >
    >
    > > On Mar 19, 9:25 pm, "Gabriel Genellina" <>
    > > wrote:

    >
    > > > En Mon, 19 Mar 2007 20:46:56 -0300, Luis M. González <luis...@gmail..com>
    > > > escribió:

    >
    > > > > What I want now is execute the script I just created.
    > > > > As far as I know, the only way to execute the script is from a command
    > > > > line and typing "setup.py py2exe".

    >
    > > > A few ways:
    > > > - os.system("commandline"). Simplest way, but you don't have much control,
    > > > and it blocks until the process finishes.
    > > > - os.popen[234]? or the functions in the popen2 module
    > > > - the subprocess module - the most complete way, but simple enough for
    > > > most cases.

    >
    > > > --
    > > > Gabriel Genellina

    >
    > > I'm sorry, but still I can't figure out this...
    > > Would you please show me a sample usage of os.system or os.popen for
    > > passing arguments to the command line?
    > > In this case, I should pass to the command line "setuppy py2exe".

    >
    > > Thanks!
    > > Luis

    >
    > aaron@athena:~$ python
    > Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
    > [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.>>> import os
    > >>> rt = os.system("ls")

    >
    > apps Firefox_wallpaper.png s2 tux_sshot_0.ppm
    > xorg.conf.diff
    > Desktop media s3 work
    > downloads permutation.py squeak workspace
    > Examples permutation.pyc trackers xorg.conf.aiglx
    >
    > >>> rt

    > 0
    >
    > This implies that `os.system("setuppy py2exe")` should do what you
    > want.




    It works!
    Thank you, this is just what I wanted.

    Luis
     
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 20, 2007
    #5
  6. Luis M. González wrote:
    > On Mar 19, 10:49 pm, "zacherates" <> wrote:
    >> This implies that `os.system("setuppy py2exe")` should do what you
    >> want.

    >
    > It works!
    > Thank you, this is just what I wanted.


    You'll get better error checking if instead you do::

    >>> import subprocess
    >>> subprocess.call(['setup.py', 'py2exe'])


    Actually, you probably should really be doing::

    >>> subprocess.call(['python', 'setup.py', 'py2exe'])


    so that you don't have to assume the OS knows how to run a .py file.

    STeVe
     
    Steven Bethard, Mar 20, 2007
    #6
  7. On Mar 19, 11:52 pm, Steven Bethard <> wrote:
    > Luis M. González wrote:
    > > On Mar 19, 10:49 pm, "zacherates" <> wrote:
    > >> This implies that `os.system("setuppy py2exe")` should do what you
    > >> want.

    >
    > > It works!
    > > Thank you, this is just what I wanted.

    >
    > You'll get better error checking if instead you do::
    >
    > >>> import subprocess
    > >>> subprocess.call(['setup.py', 'py2exe'])

    >
    > Actually, you probably should really be doing::
    >
    > >>> subprocess.call(['python', 'setup.py', 'py2exe'])

    >
    > so that you don't have to assume the OS knows how to run a .py file.
    >
    > STeVe


    Noted.
    Thanks STeVe!
     
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 20, 2007
    #7
    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. Replies:
    4
    Views:
    1,774
    Terry Hancock
    Apr 23, 2005
  2. jimgardener
    Replies:
    1
    Views:
    5,395
    Donkey Hottie
    Oct 20, 2008
  3. Swati Sharma
    Replies:
    5
    Views:
    518
    Charles Oliver Nutter
    Apr 7, 2008
  4. ashish
    Replies:
    4
    Views:
    309
    ashish
    Sep 20, 2012
  5. ashish
    Replies:
    5
    Views:
    549
    Piet van Oostrum
    Sep 20, 2012
Loading...

Share This Page