GAP can call other programs, such programs are called processes. There are two kinds of processes: first there are processes that are started, run and return a result, while GAP is suspended until the process terminates. Then there are processes that will run in parallel to GAP as subprocesses and GAP can communicate and control the processes using streams (see InputOutputLocalProcess (10.8-2)).
‣ Process( dir, prg, stream-in, stream-out, options ) | ( operation ) |
Process runs a new process and returns when the process terminates. It returns the return value of the process if the operating system supports such a concept.
The first argument dir is a directory object (see 9.3) which will be the current directory (in the usual UNIX or MSDOS sense) when the program is run. This will only matter if the program accesses files (including running other programs) via relative path names. In particular, it has nothing to do with finding the binary to run.
In general the directory will either be the current directory, which is returned by DirectoryCurrent (9.3-4) –this was the behaviour of GAP 3– or a temporary directory returned by DirectoryTemporary (9.3-3). If one expects that the process creates temporary or log files the latter should be used because GAP will attempt to remove these directories together with all the files in them when quitting.
If a program of a GAP package which does not only consist of GAP code needs to be launched in a directory relative to certain data libraries, then the first entry of DirectoriesPackageLibrary (76.3-5) should be used. The argument of DirectoriesPackageLibrary (76.3-5) should be the path to the data library relative to the package directory.
If a program calls other programs and needs to be launched in a directory containing the executables for such a GAP package then the first entry of DirectoriesPackagePrograms (76.3-6) should be used.
The latter two alternatives should only be used if absolutely necessary because otherwise one risks accumulating log or core files in the package directory.
gap> path := DirectoriesSystemPrograms();; gap> ls := Filename( path, "ls" );; gap> stdin := InputTextUser();; gap> stdout := OutputTextUser();; gap> Process( path[1], ls, stdin, stdout, ["-c"] );; awk ls mkdir gap> # current directory, here the root directory gap> Process( DirectoryCurrent(), ls, stdin, stdout, ["-c"] );; bin lib trans tst CVS grp prim thr two src dev etc tbl doc pkg small tom gap> # create a temporary directory gap> tmpdir := DirectoryTemporary();; gap> Process( tmpdi