MAF : Reference : Piping and redirection

Piping and redirection.

The information in this section pertains especially to the FSA utilities - only a few of the RWS utilities support piping.

Redirecting input

Many MAF utilities can take their input either from an ordinary disk file, or from the computer's "standard input" (henceforth called stdin). The latter behaviour is always enabled through the use of the -i command line option, which must appear before any command line argument that would otherwise be interpreted as the name of an input file.

Redirecting output

Similarly, many utilities can send their output either to an ordinary disk file or to "standard output" (henceforth called stdout). Usually output is sent to a filename derived from the name of the input file unless an explicit filename is given for the output filename. For those programs that can send output to stdout, this is enabled by using the -o command line option. It is usually better to specify an explicit filename rather than sending output to a redirected stdout, because in the latter case you will not be able to see any of the messages that the program may want to produce while it is running, which inform you of its progress so far. When you use the -o option any progress messages will appear as comments in the output. You can use the -silent option to ensure that no such messages are produced.

Piping

The ability to read from stdin and write to stdout means that MAF utilities can be used with pipes.

For example, you could minimise and sort an FSA effectively in a single command using a command line such as the following:

fsamin some_fsa -o | fsabfs -i some_fsa.canonical

Alternatively you could rely on the default output filename feature to achieve similar results, like this:

fsamin some_fsa
fsabfs some_fsa.min

In this case the final "canonical" fsa is now called some_fsa.min.bfs.

Default output and -i

If you use the -i option and don't specify an explicit filename or -o, then the output will just be sent to stdout anyway, but the output is likely to be invalid, because progress messages may be mixed up with the correct output. However, you can use -i and -o together because MAF will then adjust progress output in the usual way.

Limitations

Most of the more complex programs, notably automata itself, only accept input from a file, and can only send output to files. This is usually because the program generates several separate output files, or because later use of their output files also requires the original input file.

This is one area in which MAF is not entirely compatible with KBMAG, because many KBMAG programs will automatically read stdin if no input file is given, and in this case will automatically output to stdout. MAF utilities do not do this, because if they did so they would not give usage information if started with no command line arguments. In KBMAG output files cannot usually be given names, and the name will be similar to the default output filename in MAF. It is hoped that this will not cause problems for users familiar with KBMAG. If it does, then it should be possible to remove the incompatibility by the simple expedient of renaming the problematic MAF program and creating a small script program which accepts the equivalent KBMAG command line and then invokes the renamed program. In general MAF executables can replace KBMAG executables with the same name in GAP.