[Tutor] system()? popen2()? How to execute a command & save its output?

vijay vnbang2003 at yahoo.com
Thu Sep 30 06:44:46 CEST 2010


command_name = 'ps -ax|grep  sometext >>/tmp/output.txt'f = os.popen('%s' %command_name)
            fp = open('/tmp/output.txt')
print fp.readlines()

With Regards
Vijay


--- On Thu, 30/9/10, James Hartley <jjhartley at gmail.com> wrote:

From: James Hartley <jjhartley at gmail.com>
Subject: [Tutor] system()? popen2()? How to execute a command & save its output?
To: tutor at python.org
Date: Thursday, 30 September, 2010, 9:59 AM

I'm needing to transfer the following shell construct to Python, plus save the output of execution:

FTP_SITE='ftp.somesite.com'
ftp -a  $FTP_SITE <<EOF
binary

prompt off
cd /some_dir
dir
bye
EOF

Here, the FTP client accepts commands from STDIN, so all commands are saved in a temporary file which is redirected to the client application.

I also need to save whatever output is generated.  How can this be done in Python?


Thanks.

Jim


-----Inline Attachment Follows-----

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100930/4f2d1140/attachment.html>


More information about the Tutor mailing list