•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,580 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,582 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1653 | Replies: 7
![]() |
•
•
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation:
Rep Power: 2
Solved Threads: 3
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: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation:
Rep Power: 2
Solved Threads: 3
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Jul 2006
Posts: 562
Reputation:
Rep Power: 4
Solved Threads: 72
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
Location: Pennsylvania, US
Posts: 37
Reputation:
Rep Power: 2
Solved Threads: 3
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
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Pennsylvania, US
Posts: 37
Reputation:
Rep Power: 2
Solved Threads: 3
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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)
- Capturing Console Output (C)
- 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



Linear Mode