| | |
Capture stdin output from popen2
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 39
Reputation:
Solved Threads: 5
Hello all,
In my python application I am trying to capture the output of stdin from a command that I run via popen2(). The python docs say that it returns a tuple of (stdin, stdout) however and i run:
It only prints the results to the console and never returns a result to the variable. Whats going on?
Thanks!
-Alec Hussey
In my python application I am trying to capture the output of stdin from a command that I run via popen2(). The python docs say that it returns a tuple of (stdin, stdout) however and i run:
python Syntax (Toggle Plain Text)
result = popen2(command)[0].read()
Thanks!
-Alec Hussey
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
Well, first off there are two versions of popen2(). One is os.popen2(command), and it returns (child_stdin, child_stdout).
The other is popen2.popen2(command), and perversely, it returns (child_stdout, child_stdin).
So make sure that you don't have the two reversed.
(Who made that decision, anyways?! Grr...)
Jeff
The other is popen2.popen2(command), and perversely, it returns (child_stdout, child_stdin).
So make sure that you don't have the two reversed.
(Who made that decision, anyways?! Grr...)
Jeff
•
•
Join Date: Oct 2007
Posts: 39
Reputation:
Solved Threads: 5
I am on linux, and I am using the popen2 module.
http://docs.python.org/lib/module-popen2.html
[Edit]
Thats my mistake then isn't it? I am reading from the first element of the tuple, when I should be reading from the second one.
http://docs.python.org/lib/module-popen2.html
[Edit]
Thats my mistake then isn't it? I am reading from the first element of the tuple, when I should be reading from the second one.
Last edited by maddog39; Nov 3rd, 2007 at 9:58 pm.
•
•
Join Date: Oct 2007
Posts: 39
Reputation:
Solved Threads: 5
Yea, aaah. I intentionally put syntax errors in there to test it. But gcc is most likely printing those errors to stderr and thats why its not capturing them. Alright, I'll try it with popen3.
[Edit]
Actually, popen4() would probably work better, but whatever works I guess.
[Edit]
Now it works! Thanks alot!
[Edit]
Actually, popen4() would probably work better, but whatever works I guess.
[Edit]
Now it works! Thanks alot!
Last edited by maddog39; Nov 3rd, 2007 at 10:18 pm.
![]() |
Similar Threads
- Capturing Console Output (C)
- Multiple scripts in one file (Perl)
- Help using "include" inside of "echo" (PHP)
- Tvision TV Tuner (PCI and Add-In Cards)
- DataBase Monitoring Script (Shell Scripting)
- Bubble sort & File output jibrish errors??? (C)
- Video capture from sony VCR (Monitors, Displays and Video Cards)
- needed big time hw due and late (C)
- Help in Input output C files (C)
Other Threads in the Python Forum
- Previous Thread: def save(): print "HOW DO I DO THIS?"
- Next Thread: noob: What and when you would use Decimal vs Float Type
Views: 3087 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






