Re: [Tutor] system()? popen2()? How to execute a command save its output?
You might also consider pexpect. http://pexpect.sourceforge.net/ 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. http://docs.python.org/library/subprocess.html Cheers 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 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] system()? popen2()? How to execute a command save its output?
Hi, I've once written a script to sync my website with a local directory. I guess that you will find anything you need in the FTPHelper class. Have a look at: http://home.arcor.de/ralf_schoenian/websync/index.html At the bottom of the page you can view and download the script. Any questions are welcome. Ralf James Hartley jjhart...@gmail.com hat am 30. September 2010 um 06:29 geschrieben: I'm needing to transfer the following shell construct to Python, plus save the output of execution: FTP_SITE='ftp.somesite.com [http://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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] system()? popen2()? How to execute a command save its output?
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] system()? popen2()? How to execute a command save its output?
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 jjhart...@gmail.com wrote: From: James Hartley jjhart...@gmail.com Subject: [Tutor] system()? popen2()? How to execute a command save its output? To: tutor@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@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor