Thursday, September 24, 2009

Run python inside python and capture output

This is taken from http://techkr.blogspot.com/2007/02/python-how-to-get-output-from-ossystem.html:

How to execute python inside python and capture output:

A quick solution using popen :

import os
result=os.popen('command').read()
print result

where command is your command (expl. on windows: dir,ipconfig,...)

If you expect more than a line and want each word in a list:

import os,string
result=string.split(os.popen('dir/w').read())

4 comments:

sangeetha sathyan said...

Fabulous post admin, it was too good and helpful. Waiting for more updates.
ccna course in Chennai
Python Training in Chennai
R Programming Training in Chennai
AWS Training in Chennai
DevOps Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai
Data Science Course in Chennai

priyanka usha said...

Great job done. Excellent post for the freshers. Keep updating it.
TOEFL Coaching in Chennai
TOEFL Coaching Centres in Chennai
German Courses in Chennai
Best IELTS Coaching in Chennai
learn Japanese in Chennai
spanish language classes in chennai
TOEFL Coaching in Anna Nagar
TOEFL Coaching in Tnagar
Spoken English Class in Anna Nagar
spoken english course in anna nagar

Kayal said...

Thank you for providing the creativity post with comprehensive content. This is very helpful for gain my skill knowledge, Kindly updating...
Linux Training in Chennai
best linux training institute in chennai
Social Media Marketing Courses in Chennai
Pega Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Excel Training in Chennai
Linux Training Fees in Chennai

shiva said...

I know you feel more happy when you get things done and best of all those things are your most precious treasure.
Cyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course |
CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course