the read from standard in bug
Ken Ray
kray at sonsothunder.com
Sat Mar 15 16:19:01 EST 2003
Sadhu,
This was a post from Scott about this back in October:
------------------
We've recently received several reports of short reads from stdin in CGI
applications but have never been able to reproduce or understand this
until our own (recently upgraded) server started to show the problem.
Not sure if it's a newer version of the HTTP server software or faster
hardware or what, but sometimes "read from stdin until empty" doesn't
get all the data it should. Sometimes it doesn't get anything at all.
Now "read .. until empty" was never a good idea, merely a quick and
dirty way to read whatever should be incoming in the first bufferfull
from the HTTP server. Unfortunately the easy workaround, "read from
stdin for $CONTENT_LENGTH" also doesn't work if the process on the other
end of stdin doesn't keep up. So what you have to do instead is
something like:
put empty into buffer # this is where your data will end up
repeat until length(buffer) >= $CONTENT_LENGTH
read from stdin until empty
put it after buffer
end repeat
We'll look into supporting a simpler way to do this for 2.5 (not sure
whether to fix it so "read .. for $CONTENT_LENGTH" works, or to support
"read .. until eof" on pipes), but in the mean time something like the
above should solve the problem.
Regards,
Scott
-------------------
Hope this helps,
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
_______________________________________________
metacard mailing list
metacard at lists.runrev.com
http://lists.runrev.com/mailman/listinfo/metacard
> -----Original Message-----
> From: metacard-admin at lists.runrev.com
> [mailto:metacard-admin at lists.runrev.com] On Behalf Of
> Sadhunathan Nadesan
> Sent: Saturday, March 15, 2003 12:32 PM
> To: metacard at lists.runrev.com
> Cc: bugs at metacard.com
> Subject: the read from standard in bug
>
>
> Problem: read from stdin clips off input
>
> Scott, I request your help please. As you may recall I am
> running an older 2.4 version of the MC interpreter on my
> 2.2.16 (kernel) Linux machine and newer versions won't
> compile due to library incompatibilities. I think you said
> you were going to fix this bug after you got a faster machine
> and ran into it yourself, but I don't have that fix.
>
> So I am looking for a work around.
>
> In the case of cgi scripts, to replace the "read from stdin
> until empty" you suggested to check the content length and I
> currently use this, which works great:
>
> if ($REQUEST_METHOD = "POST") then
> put empty into buffer
> repeat until (length(buffer) >= $CONTENT_LENGTH)
> read from stdin until empty
> put it after buffer
> end repeat
> else
> read from stdin until empty
> put it into buffer
> end if
>
>
> Except, I am also running into the clipping problem on non
> cgi use, ie, when there is no content length variable to
> check. For example I have this script that I use as a
> replacement tool, and use it by piping text straight into it
> with cat or redirect
>
> #!/usr/local/bin/mc
> #*************************************************************
> ************
> #
> # Program name: replace.mt
> # Version number: 1.0
> # Author: SN
> # Date: 9/22/01
> # Description: Replace argument one with argument
> two, a filter
> #
> #*************************************************************
> ***************
>
> on startup
> read from stdin until empty
> replace $1 with $2 in it
> put it
> end startup
>
>
> What happens is that the output from this filter is chopped
> off, the trailing part of the file is missing .. but only sometimes.
>
> Of course I could rewrite this with sed and make it a shell
> script or use Perl or whatever but one cool thing about MC is
> that it is not line oriented like Unix filters so when I get
> those files from Mac guys that are just one huge line,
> everything still works. I am strongly resisting going to
> another language although that would be easy enough because I
> really want MC to be a useable scripting language for me.
>
> In any case, can you suggest a work around for the clipping
> problem that would work on 2.4 or even 2.3?
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metac> ard
>
More information about the metacard
mailing list