470,614 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Copying file descriptors

I am using the following code. It is used to spawn a new process (using
popen) and to change the file handles so that subsequent writes to
standard output with printf goes into this child process standard input.
import os

child_stdin = os.popen("cat -", "w")
old_stdout = os.dup(1)

print "foo"

os.dup2(old_stdout, 1)

It works. But the results is:
close failed: [Errno 9] Bad file descriptor
when I am using python 2.4. Note that python 2.3 did not output such an

I am guessing that upon ending the script, python tries to close
child_stdin file object, whereas the underlying file descriptor has
already been closed. Thus the error.

Does anyone knows what to do to avoir this error message?

Oct 6 '06 #1
0 965

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by François Pinard | last post: by
5 posts views Thread by John Marshall | last post: by
36 posts views Thread by Roman Mashak | last post: by
1 post views Thread by AdrianH | last post: by
5 posts views Thread by yinglcs | last post: by
2 posts views Thread by DJ Dharme | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.