Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Puzzling form/cgi problem

Reply
Thread Tools

Puzzling form/cgi problem

 
 
Dfenestr8
Guest
Posts: n/a
 
      11-02-2003
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

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      11-02-2003
Dfenestr8 wrote:
>
> 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
 
Reply With Quote
 
 
 
 
Bengt Richter
Guest
Posts: n/a
 
      11-03-2003
On Mon, 03 Nov 2003 06:23:24 +1000, "Dfenestr8" <> wrote:

>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Puzzling VPN problem with Windows 2003 John Rennie Cisco 0 03-14-2006 07:19 PM
puzzling dvd burner problem Demolitio Computer Support 10 07-17-2005 06:59 AM
Puzzling Hijack (I think) Problem Steve Meyerson Computer Support 7 09-23-2004 06:27 AM
puzzling routing problem Geert Cisco 0 04-07-2004 10:28 PM
puzzling <div> problem Richard HTML 2 09-12-2003 08:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57