Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Reading from stdi - what am I doing wrong?!

 [1/11] from: ryanc::iesco-dms::com at: 13-Jul-2001 11:52


Librarian comment

The most useful hints are from Gabriele Santilli towards the end 
of the thread (message 10).
Coincidently I am working the same problem! Chris wrote:
> Hi, > As you'll know if you've seen /zine #2, I am building an email robot. I
<<quoted lines omitted: 26>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400

 [2/11] from: ptretter:charter at: 13-Jul-2001 13:49


I would like to see more of the script. Anytime I ever use ports - I stay away from read-io and write-io. Paul Tretter

 [3/11] from: chris:starforge at: 13-Jul-2001 19:41


Hi, As you'll know if you've seen /zine #2, I am building an email robot. I have an address on my domain which pipes emails to a rebol "robot". The naive method for reading stdin in the current version is: buffer: make string! 15000 read-io system/ports/input buffer 15000 This is fine for small emails, but if I send something with an attachment - say 40k - I need to up the buffer size. Still doesn't work though - read-io only seems to pick up the first 6 or so k before stopping. If I do buffer: copy system/ports/input I get the full email.. except that buffer is a block where each line is a separate string! - I could join it all together inserting newlines after every block but with bit emails that would be /slow/. Can anyone suggest how I can read from stdin to a buffer so that the whole thing is one string and I'm sure to get the whole message in the buffer, I'm completely stuck on this one... Chris -- New sig in the works Explorer2260, Designer and Coder http://www.starforge.co.uk -- Things I'd Do If I Ever Became An Evil Overlord 39. If I absolutely must ride into battle, I will certainly not ride at the forefront of my Legions of Terror, nor will I seek out my opposite number among his army.

 [4/11] from: ryanc:iesco-dms at: 13-Jul-2001 12:27


It is not working on my server, but try this anyways: std-in: "" until [ read-io system/ports/input std-in system/options/cgi/content-length (to-integer system/options/cgi/content-length) <= length? std-in ] crlf's might not work here, because they can alter length of std-in. binary might fix that. I seem to have another problem going on, so havent got that far. Chris wrote:
> Hi, > As you'll know if you've seen /zine #2, I am building an email robot. I
<<quoted lines omitted: 26>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400

 [5/11] from: chris:starforge at: 13-Jul-2001 20:45


On 13-Jul-01, Paul Tretter wrote:
> I would like to see more of the script. Anytime I ever use ports - I stay > away from read-io and write-io.
Sending the whole script would compromise my site security, but these two demonstrate the important parts: ------------ #!/path/to/rebol REBOL [] buffer: make string! 50000 read-io system/ports/input buffer 50000 write %robot.out buffer ------------- or ---------- #!/path/to/rebol REBOL [] write %robot.out copy system/ports/input ------------- The top version works fine, until I send a large email in which case only part of it is obtained. The second version works for any size email except that I end up with {To: [address--starforge--co--uk]}{from: [chris--starforge--co--uk]}{Date: .....}{body of the email} in buffer. I haven't tested the scripts with large mails locally, but I guess the problem with the read-io version is that it's not waiting for all the email to come in. The copy would work fine, if it gave me the email as one big strings with newlines intact... Chris -- New sig in the works Explorer2260, Designer and Coder http://www.starforge.co.uk -- A formal parsing algorithm should not always be used. -- D. Gries

 [6/11] from: chris:starforge at: 13-Jul-2001 20:37


On 13-Jul-01, Ryan Cole wrote:
> It is not working on my server, but try this anyways: > std-in: "" > until [ > read-io system/ports/input std-in system/options/cgi/content-length > (to-integer system/options/cgi/content-length) <= length? std-in > ]
That sort of thing will only work with cgi data - I need to be able to literally pipe in a file, ie: my script needs to be able to handle (contrived example time..) cat an_email | myscript.r An email forwarder on my site does: [address--starforge--co--uk] -> |/home/starforg/..../scgi-bin/scriptname.r which does basically the same thing - emails sent to [address--starforge] are piped into the rebol script. Using copy would work fine (aside from security implications) if it didn't stick each line in a separate string. :/ Chris -- New sig in the works Explorer2260, Designer and Coder http://www.starforge.co.uk -- Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month. -- Wernher von Braun

 [7/11] from: ryanc:iesco-dms at: 13-Jul-2001 13:00


try adding this... Chris wrote:
> #!/path/to/rebol > > REBOL [] >
set-modes system/ports/input [lines: false]

 [8/11] from: agem:crosswinds at: 14-Jul-2001 0:17


RE: [REBOL] Re: Reading from stdi - what am I doing wrong?! [chris--starforge--co--uk] wrote:
> On 13-Jul-01, Paul Tretter wrote: > > I would like to see more of the script. Anytime I ever use ports - I stay
<<quoted lines omitted: 17>>
> part of it is obtained. The second version works for any size email except that > I end up with
vague remembering read-io does not wait it returns 0 if there is no more data, lenght otherwise something like buffer: make string! 100000 until[ wait port 0 = read-io port tail buffer 100000] could work.
> {To: [address--starforge--co--uk]}{from: [chris--starforge--co--uk]}{Date: .....}{body > of the email}
<<quoted lines omitted: 3>>
> one big strings with newlines intact... > Chris
-Volker

 [9/11] from: chris:starforge at: 14-Jul-2001 8:50


On 13-Jul-01, Ryan Cole wrote:
> try adding this... > set-modes system/ports/input [lines: false]
Nearly there, [lines: false binary: false] works though :))) I'm happy now. Now to get the rest of the robot back in place! Chris -- New sig in the works Explorer2260, Designer and Coder http://www.starforge.co.uk -- Antonym, n.: The opposite of the word you're trying to think of.

 [10/11] from: g:santilli:tiscalinet:it at: 14-Jul-2001 14:49


Hello Chris! On 13-Lug-01, you wrote: C> I get the full email.. except that buffer is a block where C> each line is a separate string! - I could join it all together system/ports/input is opened with the /lines refinement. You can open your own port this way: stdin: open/binary console:// ; so you can get binary input too buffer: copy/part stdin system/options/cgi/content-length close stdin or, as a single line: buffer: read/binary/part console:// system/options/cgi/content-length Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [11/11] from: g:santilli:tiscalinet:it at: 14-Jul-2001 14:54


Hello Chris! On 13-Lug-01, you wrote: C> Using copy would work fine (aside from security implications) C> if it didn't stick each line in a separate string. :/ Then just drop the /part refinement in the examples I provided in the previous email. :) Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted