[Gambas-user] getting process output reliably

Benoit Minisini gambas at ...1...
Wed Aug 11 20:57:02 CEST 2004


On Wednesday 11 August 2004 20:27, Rob wrote:
> 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.

You should not use Lof() on a process output, because there is no mean to know 
how many bytes are readable without read them. You should use "READ #LAST, 
sshLine, -256" to read, for example, at most 256 bytes.


>
> 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!

End of line is '\n', not '\r\n'. And Line input will stop if there is no data 
on the process output, even if it is not and end of line. Use READ as I shown 
just before.

>
> 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
>

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list