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

Chris Fuller cfuller084 at thinkingplanet.net
Thu Sep 30 07:00:34 CEST 2010

You might also consider pexpect.

It's designed for interactive console applications like ftp.

For popen() style access, the recommended approach is the subprocess module.  
You should be able to find an example in the docs to fit your application.


On Wednesday 29 September 2010, James Hartley 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
> 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

More information about the Tutor mailing list