Can't spawn, or popen from daemon

Jeff Epler jepler at unpythonic.net
Wed Apr 21 07:20:33 EDT 2004


Imagine that /usr/bin/lp has something like the following Python code at
the top:
    sys.stderr.write("something\n")
sys.stderr (stdio's stderr in C) in the called program is closed, so
this will return an error.  Whatever the error was, lp may be trying to
print *that* to stderr, too.  If there's some sort of failure, you're
not going to see the message.

You could try:
     os.popen('/usr/bin/lp -d printer1 %s 2>&1' % (filename))
to capture both stdout and stderr, or you could use the popen2 module to
get multiple handles for I/O with the child, or you could try (in
daemonize):
    nullfd = os.open("/dev/null", os.O_RDWR)
    os.dup2(nullfd, 0)
    os.dup2(nullfd, 1)
    os.dup2(nullfd, 2)
    os.close(nullfd)
to make the standard C files point at /dev/null (writes succeed, but the
data is discarded), in case it's an error reading stdin or writing to
stderr that is killing lp.

Jeff




More information about the Python-list mailing list