cgi integration question 2
ken at hotmail.com
Sun Oct 20 18:20:08 CEST 2002
"Gerhard Häring" <gerhard.haering at gmx.de> wrote in message
news:slrnar5gqs.hg.gerhard.haering at lilith.my-fqdn.de...
> Ken wrote in comp.lang.python:
> > Hello, I have this problem which I don't know what it means or how
> > to fix, can someone help me?
> > Traceback (most recent call last): File "chessboard.cgi", line 143, in ?
> > outf.close() IOError: [Errno 32] Broken pipe
> Dunno why, but I have a few remarks nonetheless.
> > Python frontend program:
> > lines = 
> > outf, inf = os.popen2("knight")
> > print >>outf, size #size
> > print >>outf, startX #start X position
> > print >>outf, startY #start Y position
> > outf.close() #<<========= Refer to this line 143
> > time.sleep(1)
> Frankly, sleeping in the context of synchronous IO doesn't make any
> > maxSize = string.atoi(size) * string.atoi(size)
> > while len(lines)< maxSize:
> > lines = inf.readlines() #Output produce by back end program ["34",
> > ...etc]
> readlines() reads the *whole* output, so if after that you read again,
> it will block forever. If you want to read line by line, use
> readline() instead. But read the docs about read() and readline(), as
> you'll find important info there, for example that if it returns an
> empty string it means that you've reached EOF :-)
> > if len(lines)==maxSize:
> > inf.close()
> > break
> > time.sleep(1)
> You could rewrite this as:
> outf, inf = os.popen2("night")
> print >>outf, ...
> lines = inf.readlines()
> -- Gerhard
Hi, I think my problem here is that the backend program can't output ontime
and I got an empty list in return. Does lines = inf.readlines() actually
wait for the backend program to finish execution before proceeding to
I find it very strange that when I compile using python scriptfile.cgi in
telnet environment, it works fine, but when I put on the web browser, the
list is empty. Do you know how I can fix this problem?
My original program's segment:
function = "3"
lines = 
if function=="3" and size!="" and startX!="" and startY!="":
#Execute Backend program
outf, inf = os.popen2("knight")
print >>outf, size
print >>outf, startX
print >>outf, startY
lines = inf.readlines()
print lines #empty on web browser, ok in telnet
More information about the Python-list