[Gambas-user] Conflicting and bewildering help for pipes

Tobias Boege taboege at ...626...
Thu Oct 24 15:08:31 CEST 2013


On Thu, 24 Oct 2013, Bruce wrote:
> >From "Stream & input/Output functions"|"PIPE":
> 
> 1. If I specify READ WATCH then according to the help "If at least one
> byte can be read from the pipe, then the event handler File_Read() is
> called." but what is the name of event handler. Surely it cant be
> "File_Read"?
> 

Are you using some rhetorical figure which I don't understand? Or is this
really your question? :-)

You write the event handler:

Public Sub File_Read()
  ' Gets called when at least one byte is readable from the Pipe.
End

File_Read() *really* is the name of the event handler.

> 2. According to the first example, it opens a pipe FOR INPUT. Surely
> this is incorrect.
> 

Yes. "INPUT" is to be replaced by "READ". I did this and converted the
uppercase keywords to the Gambas3-style capitalised equivalents.

> 3. (Not help related) If I want to catch output from a shelled command
> then what order to I have to do things? I am trying to use two pipes to
> communicate with a gnuplot process, one to send commands and one to
> catch any error output.
>   hGPpipe = Pipe "/tmp/gnuplotFIFO1" For Write
>   hGPstdout = Pipe "/tmp/gnuplotFIFO2" For Read Watch 
>   hGPproc = Shell "gnuplot < /tmp/gnuplotFIFO1 > /tmp/gnuplotFIFO2"
> 
> Sending commands by writing to hGPpipe works OK (sort of, there are
> instances of junk getting in there.) but I can't figure out how to catch
> the output?
> 

I have problems, too. The first thing I notice is that your code should not
work at all. If you open a Pipe For Read, the interpreter will sit waiting
until someone opens the same pipe for writing. hGPproc is the desired writer
but you don't get to the point where the writer is actually started because
you wait on the Pipe ... For Read line. If your program starts gnuplot, I'll
be surprised.

My workaround always was like this:

  ' Create the read pipe special file
  hGPstdout = Pipe "/tmp/gnuplotFIFO2" For Write
  Close #hGPstdout
  ' Create write end
  hGPpipe = Pipe "/tmp/gnuplotFIFO1" For Write
  ' Start writer
  hGPproc = Shell "gnuplot </tmp/gnuplotFIFO1 >/tmp/gnuplotFIFO2"
  ' Really create read end
  hGPstdout = Pipe "/tmp/gnuplotFIFO2" For Read Watch

Note that since the shell which starts hGPproc already opened
/tmp/gnuplotFIFO2, you won't have any deadlock problems when opening
hGPstdout For Read afterwards.

Anyway, if I

  Print #hGPpipe, "plot x^2"

only garbage (not non-sense but the string is always scrambled) seems to
arrive at gnuplot. Also, I seem to get output from gnuplot irregularly. So
I'm out of options for now. I remember that raising Read events for streams
has been subject to issues from time to time...

Regards,
Tobi




More information about the User mailing list