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

James Hartley jjhartley at gmail.com
Thu Sep 30 19:49:07 CEST 2010

On Thu, Sep 30, 2010 at 7:27 AM, R. Alan Monroe <amonroe at columbus.rr.com>wrote:

> >> 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
> NB: If you use the ftp module (which works great), be sure to open all
> files in Binary mode. Voice of experience here.

Thanks all, for the responses thus far.  I was not aware of the ftplib
module.  This looks like it will take care of most of my needs.

However, output from these FTP commands are sent to stdout.  Is there a way
to redirect/capture stdout, as I need to parse the directory listings?

Thanks, again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100930/a553be33/attachment.html>

More information about the Tutor mailing list