Puzzling form/cgi problem

D

Dfenestr8

Hi.

I have a problem with a subroutine in a cgi script that's supposed to
return the byte location at the end of a file, which the script then
stores as a hidden input on a web form.

Unfortunately, even though it works fine in the python shell, in the
cgi-script it always returns "0". That's no use to me at all.

Here's the subroutine......

def getLastByteLoc(log):
#open log file
f = open(log)

#seek to end of log file.
f.seek(0,2)

location = f.tell()
f.close()
return location
 
P

Peter Hansen

Dfenestr8 said:
I have a problem with a subroutine in a cgi script that's supposed to
return the byte location at the end of a file, which the script then
stores as a hidden input on a web form.

Unfortunately, even though it works fine in the python shell, in the
cgi-script it always returns "0". That's no use to me at all.

Not sure about a fix for the seek() problem, by can't you just use
os.stat() to get the size of the file?

-Peter
 
B

Bengt Richter

Hi.

I have a problem with a subroutine in a cgi script that's supposed to
return the byte location at the end of a file, which the script then
stores as a hidden input on a web form.

Unfortunately, even though it works fine in the python shell, in the
cgi-script it always returns "0". That's no use to me at all.
If you want to use that routine, you might want to return something distinctive in case
of exceptions. E.g., perhaps the cgi prog can't see the file the way you are specifying it
(is it a full path? Is that legal in the context of the cgi, which are sometimes constrained
to access down a particular subtree?) or doesn't have adequate permissions (cgi is probably
running as "nobody" or some other server user id, and running in a different default directory).
Here's the subroutine......

def getLastByteLoc(log):
#open log file
f = open(log)

#seek to end of log file.
f.seek(0,2)

location = f.tell()
f.close()
return location

Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top