Running an external command from within a Python script 
Author Message
 Running an external command from within a Python script

Can anyone tell me who to run an external command from within a python
Script?

I have written a web page which calls a Python script and puts a
comment, name and email address into a temp file.  I have installed an
exe file (Blat.exe) on our web server which will send a text file via
email to someone else.  How can I execute this exe file from within the
Python script??

Thanks for any replies.

Rico



Tue, 03 Apr 2001 03:00:00 GMT  
 Running an external command from within a Python script

Quote:

> Can anyone tell me who to run an external command from within a Python
> Script?

    OK, here's a simple answer to your simple question:

Python 1.5.1 (#2, Sep 14 1998, 15:28:00) [C] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

Quote:
>>> import os
>>> os.system('dir')

LINUX.tar.gz  mail          replcomps     wall.jpg      xx.pl
SUN.tar.gz    pcd           ric009.pcd    xx.jpg
0

    I'm not sure about the implementation of os.system under Windows (which I
assume from the .exe extension mentioned below). The system() call is
implemented in the posix module (which is integrated into the os module
whenever possible) - and I think Windows does some POSIX, but I can't test that
right now...

Quote:
> I have written a web page which calls a Python script and puts a
> comment, name and email address into a temp file.  I have installed an
> exe file (Blat.exe) on our web server which will send a text file via
> email to someone else.  How can I execute this exe file from within the
> Python script??

    Now for a better response to your question :)

    The use of system() is kinda frowned upon in CGI systems because of various
security concerns. It's also not very portable (between different Operating
Systems) - and if there's one thing we like in Python, it's portability :)

    If you want to send email from a Python script, then consider using the
standard module smtplib instead,
       http://www.python.org/doc/lib/module-smtplib.html

         Richard

--
Richard Jones,  developer for the Fulcrum Consulting Group.   (03) 9621 2100
http://www.fulcrum.com.au/         http://alumni.dgs.monash.edu.au/~richard/



Tue, 03 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to run external command within f program?

2. Running a TK script using wish80.exe within a tcl script

3. Running scripts within scripts

4. python-mode - running a script that takes command line arguments

5. Odd problem running command-line python scripts (win2k)

6. Run Python script in command line

7. run external .exe files within an ada program..

8. run external .exe files within an ada program..

9. Problem with consecutive running of a gawk script within a loop

10. Run awk from within sed script?

11. shell commands within awk script

12. Simple awk command within a perl script

 

 
Powered by phpBB® Forum Software