I/O drivers
The mmsystem module provides two IO drivers: the first one allows to use a string or text object as a file and the second connects a Mosel input or output stream to a program started in a different process. Using this driver, it is possible to get the output of an external program (for instance the result of a preprocessor to feed the Mosel compiler) or implement a basic bidirectional inter process communication thanks to the openpipe procedure (which relies on this IO driver).
Driver text
text:ident
This driver uses a model variable of type string or text as its input or output media. The ident argument it requires is therefore the name of this variable that must be declared globally public to the model or have been published with publish (such that it can always be found independently of the compiler settings).String objects can only be accessed for reading while text entities can be used for both reading and writing.
In the following example the constant string "T" is used as the initialization file for variable "A":
declarations public T="A:123" A:integer end-declarations initializations from "text:T" A end-initializations
Driver pipe
pipe:program [options...]
The file name for this driver is an external program with its options. Options are separated by spaces or tabulations and may be quoted using either single or double quotes. A quoted option may contain any kind of character except the quote used to delimit the string.
When the system opens a pipe, a new process is started for executing the given program and default input and output streams are directed to system pipes. If the file is open for reading (resp. writing), the default ouput stream (resp. input stream) of the new process becomes the current input stream (resp. output stream) of the model. To locate the program to be executed, the system relies on the PATH environment variable. Detection of error (typically the program cannot be found or is not executable) differs depending on the operating system: under Windows, the error is reported immediately and the pipe is not open. With Posix systems, no error is reported but following IO operations fail.
When the file is closed, both input and output streams of the external process are closed then the system waits for its termination: in order to avoid a lock up of the Mosel program one must make sure that the external program ends its execution when default input and output streams are closed.
Example: the following command could be used with Mosel Console for compiling the model mymod.mos after it has been processed by the C preprocessor. Note that we have to provide an output file name since the compiler cannot deduce it from the source file name.
For a Posix systems:
compile 'mmsystem.pipe:cpp mymod.mos' '' mymod.bim
For Windows (with MSVC):
compile 'mmsystem.pipe:cl /E mymod.mos' '' mymod.bim
When Mosel is running in restricted mode (see Section mosel command: restricted mode), this driver behaves like the system procedure.