473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

closing stdin, stdout and stderr

I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn

Dec 26 '05 #1
5 3529
Martijn Brouwer wrote:
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn

I've had excellent results with variants of the cookbook entry at

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731

--
Robin Becker
Dec 26 '05 #2
Robin Becker wrote:
Martijn Brouwer wrote:
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn

I've had excellent results with variants of the cookbook entry at

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731

but perhaps you're using a non unix OS, which will make that recipe wrong.

--
Robin Becker
Dec 26 '05 #3
On Mon, 2005-12-26 at 23:13 +0000, Robin Becker wrote:
Martijn Brouwer wrote:
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn

I've had excellent results with variants of the cookbook entry at

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731


I read this one, which was the reason that I tried os.close instead of
sys.stdXXX.close(). But I would like to know why it does not close a
file discriptor is I call its close method().
Martijn

--
Martijn Brouwer <e.***********@alumnus.utwente.nl>

Dec 27 '05 #4
On Mon, 2005-12-26 at 23:15 +0000, Robin Becker wrote:
Robin Becker wrote:
Martijn Brouwer wrote:
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could not print anymore, so
this seemed to work. However, later I noticed that they were not really
closed. When I close them using os.close(), it did work.
What is the difference between these two methods and what is the reason
behind it? It took me a day to find out why I could not log out after
starting the daemon.

Martijn

I've had excellent results with variants of the cookbook entry at

http://aspn.activestate.com/ASPN/Coo.../Recipe/278731

but perhaps you're using a non unix OS, which will make that recipe wrong.


Well, I am writing a unix daemon ;)

Martijn
Dec 27 '05 #5
In article <ma***************************************@python. org>,
Martijn Brouwer <e.***********@alumnus.utwente.nl> wrote:
....
I read this one, which was the reason that I tried os.close instead of
sys.stdXXX.close(). But I would like to know why it does not close a
file discriptor is I call its close method().


They're special. I suppose because of internal dependencies - last
chance exception handler etc. - they are created without a close
function, internally, so close() has no effect. I don't know if it
really makes any sense, since anyway one may close the file descriptors
directly as you did.

Donn Cave, do**@u.washington.edu
Dec 27 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
4
by: Jan Knop | last post by:
Hello I am writing a Windows application where I need to redirect stdin, stdout and stderr from Python. to my application Is it a simple way of do it ? Has anyone done it using Winsock ?
0
by: lickspittle | last post by:
Hi, I have Python embedded with my other code, and when my other code opens a console and redirects stdout, stdin and stderr to it, then calls PyRun_InteractiveLoop, it immediately returns with...
23
by: herrcho | last post by:
What's the difference between STDIN and Keyboard buffer ? when i get char through scanf, i type in some characters and press enter, then, where do the characters go ? to STDIN or Keyboard...
6
by: ccdrbrg | last post by:
What is the best way to protect stdin within a library? I am writing a terminal based program that provides plugin capability using the dlopen() API. Sequencing program commands (typed) and...
13
by: Vincent Delporte | last post by:
Hi I'm a Python newbie, and would like to rewrite this Perl scrip to be run with the Asterisk PBX: http://www.voip-info.org/wiki/view/Asterisk+NetCID Anyone knows if those lines are...
2
by: kimonp | last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki. I am trying to call a perl function from within php using proc_open. The perl script is being executed and...
0
by: Gabriel Genellina | last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com> escribió: Use subprocess.PIPE Usually the tricky part is to figure out exactly whether there is more input or not. With...
8
by: subramanian100in | last post by:
The file stdio.h just contains extern FILE *stdin; extern FILE *stdout; extern FILE *stderr; When are the standard streams stdin, stdout, stderr initialiazed ? How are they initialiazed ? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.