6.23.9 Pipes

In addition to using Gforth in pipes created by other processes (see Gforth in pipes), you can create your own pipe with open-pipe, and read from or write to it.

open-pipe ( c-addr u wfam – wfileid wior ) gforth-0.2 “open-pipe”

c-addr u is the name/path of an OS-level program. If wfam is r/o, the standard output of the program is piped into the Gforth process and can be read from wfileid. If wfam is w/o, data written to wfileid is piped as standard input into the program. wior is 0 if and only if opening the pipe succeeded.

close-pipe ( wfileid – wretval wior ) gforth-0.2 “close-pipe”

Closes a pipe wfileid opened with open-pipe

If you write to a pipe, Gforth can throw a broken-pipe-error; if you don’t catch this exception, Gforth will catch it and exit, usually silently (see Gforth in pipes). Since you probably do not want this, you should wrap a catch or try block around the code from open-pipe to close-pipe, so you can deal with the problem yourself, and then return to regular processing.

broken-pipe-error ( – n  ) gforth-0.6

the error number for a broken pipe