Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Bad file descriptor Date: Thu, 13 Nov 2014 19:41:22 -0500 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 45 Message-ID: References: <442861d9-4280-4222-9084-f626a7782161@googlegroups.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1415925682 6237 127.0.0.1 (14 Nov 2014 00:41:22 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 14 Nov 2014 00:41:22 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:80734 In article , Ben Finney wrote: > satishmlmlml@gmail.com writes: > > > import os > > os.write(1, b'Hello descriptor world\n') > > OSError: Bad file descriptor > > It works fine for me:: > > >>> import os > >>> os.write(1, b'Hello descriptor world\n') > Hello descriptor world > 23 > > You don't say which Python, or which version, you're using. In the > absence of different information, most of us will assume the latest > stable release of CPython. Currently, that is CPython 3.4. I don't think this has anything to do with which version of Python he's using. I think all that's happening is (for some unknown reason), fd 1 is closed before his program runs. You can demonstrate this, for example, in bash: $ cat hello.py import os os.write(1, b'Hello descriptor world\n') $ python hello.py Hello descriptor world $ 1<&- python hello.py Traceback (most recent call last): File "hello.py", line 2, in os.write(1, b'Hello descriptor world\n') OSError: [Errno 9] Bad file descriptor You owe the Oracle 5 minutes of his life back and a cookie for making him read enough of the bash manual to figure out the syntax to tell it to close a descriptor.