[Tutor] system()? popen2()? How to execute a command & save itsoutput?
R. Alan Monroe
amonroe at columbus.rr.com
Thu Sep 30 16:27:43 CEST 2010
>> 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
> Are you sure? It looks like you would be better writing a python
> program
> using the ftp module. Shells are intended to execute external programs
> but Python provides the tools to do the job directly from Python, with
> no need to start external programs in most cases.
NB: If you use the ftp module (which works great), be sure to open all
files in Binary mode. Voice of experience here.
Alan
More information about the Tutor
mailing list