at / os.popen problems
Robert Vollmert
rvollmert at gmx.net
Sat Jul 17 10:53:26 EDT 1999
Hello,
I found a problem with os.popen in an at job. Closing the pipe after
calling pipe.read() produces an IOError for some commands.
popen.py (attached) produces the following output when called from at
as:
popen.py '/bin/ls /' '{ /bin/ls / ; }' 'echo hello' '{ echo hello ; }'
error while closing { /bin/ls / ; }: IOError: [Errno 10] No child processes
error while closing echo hello: IOError: [Errno 10] No child processes
error while closing { echo hello ; }: IOError: [Errno 10] No child processes
/bin/ls / status: 0
/bin/ls / output:
[snipped correct ls output]
{ /bin/ls / ; } status: -1
{ /bin/ls / ; } output:
[snipped correct ls output]
echo hello status: -1
echo hello output:
hello
{ echo hello ; } status: -1
{ echo hello ; } output:
hello
This works correctly from cron and in the shell. Also, when read()
is left out, close() works as normal.
I'm using a self-compiled version 1.5.2 python on Debian/GNU Linux 2.1
with kernel 2.2.10. at is version 3.1.8.
Thanks,
Robert.
popen.py:
#! /usr/bin/env python
import sys, os, string
def main():
for command in sys.argv[1:]:
try:
pipe = os.popen('%s' % command, 'r')
except Exception, inst:
sys.stderr.write('error while opening %s: %s\n' %
(command, inst.__class__.__name__, inst))
try:
output = pipe.read()
except Exception, inst:
sys.stderr.write('error while reading %s: %s\n' %
(command, inst.__class__.__name__, inst))
try:
status = pipe.close() or 0
except Exception, inst:
sys.stderr.write('error while closing %s: %s: %s\n' %
(command, inst.__class__.__name__, inst))
status = -1
print command, "status:", status
print command, "output:"
print output
if __name__ == '__main__':
sys.exit(main())
--
Robert Vollmert rvollmert at gmx.net
More information about the Python-list
mailing list