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).
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 Directories) 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
DirectoryCurrent (see DirectoryCurrent)
--this was the behaviour of GAP 3--
or a temporary directory returned by
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 should be
The argument of
DirectoriesPackageLibrary 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
DirectoriesPackagePrograms 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, 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( tmpdir, ls, stdin, stdout, ["-c"] );; gap> PrintTo( Filename( tmpdir, "emil" ) ); gap> Process( tmpdir, ls, stdin, stdout, ["-c"] );; emil
prg is the filename of the program to launch, for portability it should
be the result of
Filename (see Filename) and should pass
Process does no searching through a list of directories,
this is done by
stream-in is the input stream that delivers the characters to the
For portability it should either be
InputTextNone (if the process reads
InputTextUser, the result of a call to
from which no characters have been read, or the result of a call to
Process is free to consume all the input even if the program itself
does not require any input at all.
stream-out is the output stream which receives the characters from the
For portability it should either be
OutputTextNone (if the process
writes no characters),
OutputTextUser, the result of a call to
OutputTextFile to which no characters have been written, or the result
of a call to
options is a list of strings which are passed to the process as command line argument. Note that no substitutions are performed on the strings, i.e., they are passed immediately to the process and are not processed by a command interpreter (shell). Further note that each string is passed as one argument, even if it contains space characters. Note that input/output redirection commands are not allowed as options.
In order to find a system program use
gap> path := DirectoriesSystemPrograms();; gap> date := Filename( path, "date" ); "/bin/date"
date with no argument and no input, collect the output into
a string stream.
gap> str := "";; a := OutputTextString(str,true);; gap> Process( DirectoryCurrent(), date, InputTextNone(), a,  ); 0 gap> CloseStream(a); gap> Print(str); Fri Jul 11 09:04:23 MET DST 1997
Exec runs a shell in the current directory to execute the command given
by the string cmd with options
, ..., optionN
gap> Exec( "date" ); Thu Jul 24 10:04:13 BST 1997
cmd is interpreted by the shell and therefore we can make use of the various features that a shell offers as in following example.
gap> Exec( "echo \"GAP is great!\" > foo" ); gap> Exec( "cat foo" ); GAP is great! gap> Exec( "rm foo" );
Exec calls the more general operation
Process (see Process).
Edit (see Edit) should be used to call an editor from within GAP.
[Top] [Up] [Previous] [Next] [Index]
GAP 4 manual