469,903 Members | 1,623 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

How to run a program?

I'm writing a code that checks the header of .po file
for syntax errors. I want this program to run
msgfmt.py on the .po file first & then the rest.

How can you write a code that runs another program in
itself?

:),
Sara

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Jul 19 '05 #1
2 1424
please read the documentation for subprocess,
http://docs.python.org/lib/node230.html

Jul 19 '05 #2
On Sat, 30 Apr 2005 03:35:58 -0700 (PDT), Sara Khalatbari
<sa************@yahoo.com> declaimed the following in comp.lang.python:
I'm writing a code that checks the header of .po file
for syntax errors. I want this program to run
msgfmt.py on the .po file first & then the rest.

How can you write a code that runs another program in
itself?
Short answer is: start by reading the library reference on "os"
module (and expand outward if what you need is in "os").

However... Do you also control the source code for msgfmt.py?

If so, you might be able to set it up similar to "worker.py" in
my example, and invoke it directly /as part of/ your new program, not as
an external program.

worker.py
=========
# the importable yet stand-alone module

import sys

# very simple program, it just prints the contents of the supplied
argument

def theWork(arg):
print "The argument is: %s" % arg

if __name__ == "__main__":
for a in sys.argv[1:]: # skip the program name in argv[0]
theWork(a)
and a sample caller...

caller.py
=========
# the caller module

import worker

worker.theWork("This is the invoked version")
This scheme still lets "worker" be used as a stand-alone
program, yet it can be invoked internal to another program. Sample
output:

E:\UserData\Dennis Lee Bieber\My Documents> worker.py a 1 2 b
The argument is: a
The argument is: 1
The argument is: 2
The argument is: b

E:\UserData\Dennis Lee Bieber\My Documents>python worker.py a 1 2 b
The argument is: a
The argument is: 1
The argument is: 2
The argument is: b

E:\UserData\Dennis Lee Bieber\My Documents>caller.py
The argument is: This is the invoked version

E:\UserData\Dennis Lee Bieber\My Documents>
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by edgrsprj | last post: by
11 posts views Thread by christopher diggins | last post: by
1 post views Thread by Eric Whittaker | last post: by
9 posts views Thread by Hemal | last post: by
7 posts views Thread by ibtc209 | last post: by
Banfa
2 posts views Thread by Banfa | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.