A stream is opened for input or output by means of the open/3 predicate. The goal
opens a communication channel with the file specified by File.open(File, Mode, Stream)
File may be an atom or a string, and takes the form of a file name in the host machine environment. In the UNIX environment, file names can take several forms:
Mode is one of the atoms read, write, append, update or string, where the stream is to be opened for input, output, output at the end of the existing file, both input and output or to a string, respectively. Opening a file in write mode will create it if it does not exist, and erase the previous contents if it does exist. Opening a file in append mode will keep the current contents of the file and start writing at its end. The mode string specifies a stream to/from a string and is described in detail in section .
Stream is a logical stream identifier or an uninstantiated variable. The stream identifier may then be used in predicates which have a named stream as one of their arguments. For example
will write the atom subject to the file `foo'. A stream Stream opened by the open/3 predicate may be subsequently closed by the callopen(`foo', update, stream), write(stream, subject)
The predicateclose(Stream)
opens a pipe, i.e. two streams, In for reading and Out for writing, which are connected together using the pipe(2) system call. This mechanism is normally used to communicate with other processes which were forked by the main process, but it can also be used to temporarily store some data instead of writing it into a file, however for this purpose a string stream is more efficient. Before any reading is possible, the output must be usually flushed with flush/1. The term being read from the input end of the pipe must be written in a valid Prolog syntax, and so it must be terminated by a fullstop. An example of its use:pipe(In, Out)
If too much data is written into the pipe without reading it, ECLiPSe may be suspended by the operating system.[eclipse 1]: pipe(in, out). yes. [eclipse 2]: write(out, "output_term(args).\n"), flush(out). yes. [eclipse 3]: read(in, X). X = output_term(args) yes.