[Gambas-user] getting process output reliably

Rob sourceforge-raindog2 at ...94...
Wed Aug 11 20:27:07 CEST 2004


I have a little dilemma regarding the Process_Read event.  
Basically, if you use the READ statement like so:

  IF NOT Eof(LAST) THEN
    READ #LAST, sshline, Lof(LAST)
  ENDIF

you seem to get 16 bytes at a time, firing Process_Read events in 
quick succession, and eventually the READ statement dies with an 
EOF encountered.  If you put a TRY in front of it, it doesn't 
die, but you lose output left and right.

My workaround for this has been to use LINE INPUT as follows:

  DO WHILE NOT Eof(LAST)
    LINE INPUT #LAST, sshline
    IF Right(sshline,1) = "\r" THEN sshline = sshline & "\n"
    sshbuf.Add(sshline,0)
  LOOP

I add a "\n" if the line ends in a "\r" because LINE INPUT strips 
off "\n" from whatever it reads, if it's present.  But sometimes 
LINE INPUT reads data that ends in "\r" but has no linefeed at 
the end, and in those cases my program ends up with an 
extraneous linefeed!

I am prepared to patch LINE INPUT's behavior in the Gambas 
interpreter if I have to, but I'd like to know if there's 
another workaround I haven't considered.... maybe some 
undocumented parameter to LINE INPUT?

Rob





More information about the User mailing list