473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing arguments to a command line from a python script

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

Mar 19 '07 #1
6 2836
En Mon, 19 Mar 2007 20:46:56 -0300, Luis M. González <lu*****@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

Mar 20 '07 #2
On Mar 19, 9:25 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
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
Mar 20 '07 #3
On Mar 19, 9:42 pm, "Luis M. González" <luis...@gmail.comwrote:
On Mar 19, 9:25 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
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.

Mar 20 '07 #4
On Mar 19, 10:49 pm, "zacherates" <zachera...@gmail.comwrote:
On Mar 19, 9:42 pm, "Luis M. González" <luis...@gmail.comwrote:
On Mar 19, 9:25 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
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

Mar 20 '07 #5
Luis M. González wrote:
On Mar 19, 10:49 pm, "zacherates" <zachera...@gmail.comwrote:
>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
Mar 20 '07 #6
On Mar 19, 11:52 pm, Steven Bethard <steven.beth...@gmail.comwrote:
Luis M. González wrote:
On Mar 19, 10:49 pm, "zacherates" <zachera...@gmail.comwrote:
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!


Mar 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned...
2
by: John Leslie | last post by:
I am porting a script from Korn Shell to python and want to pass named parameters like -JOB 123456 -DIR mydir I can get it to work passing --JOB and --DIR but not -JOB and -DIR Any ideas? ...
1
by: Casey Bralla | last post by:
I've got a python cgi-bin application which produces an apache web page. I want to pass arguments to it on the URL line, but the parameters are not getting passed along to python properly. I've...
6
by: Jon Hewer | last post by:
hi i am writing a little script and currently implementing command line arguments following the guide by mark pilgrim from dive into python; ...
5
by: Chris Hieronymus | last post by:
Hi, I have a bunch of x-y data contained in an array. I would like to plot the data using an external program (psxy in GMT). The plotting program takes x-y couples as standard input. ...
3
by: Rocky Zhou | last post by:
I wonder is there any way to make the wrapper program can wrap options && arguments for the the subprocess/command the wrapper will execute? by getopt or optparse module? This is something...
5
by: kyosohma | last post by:
I have created what amounts to a simple GUI email sending program using Python + wxPython. I have modified the mailto registration in the Windows Registry so that it launches the script when...
4
by: Keith Hughitt | last post by:
Hi all, I am using someone else's script which expects input in the form of: ./script.py <arg1arg2 I was wondering if the angle-brackets here have a special meaning? It seems like they...
3
by: vijayarl | last post by:
Hi all, i have perl script, which is used to send mail. its a command line utility. if we run this perl script in command line by passing all it's required arguments, it works very well.there no...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.