Previous Up Next

20.2  Environment Access

A number of predicates and global flags is provided to get more or less useful information from the operating system environment.

20.2.1  Command Line Arguments

Arguments provided on the UNIX (or DOS) command line are accessed by the built-ins argc/1 which gives the number of command line arguments (including the command name itself) and argv/2 which returns a requested positional argument in string form. If the first argument of argv/2 is the atom all, then a list of all command line arguments is returned.

20.2.2  Environment Variables

On UNIX, environment variables are another way to pass information to the ECLiPSe process. Their string value can be read using getenv/2:

[eclipse 1]: getenv('HOME', Home).

Home = "/usr/octopus"

The environment variables available on Window is version dependent, and is not a recommended method of passing information.

20.2.3  Exiting ECLiPSe

When ECLiPSe is exited, it can give a return code to the operating system. This is done by using exit/1. It exits ECLiPSe and returns its integer argument to the operating system.

[eclipse 1]: exit(99).
csh% echo $status

Note that halt is equivalent to exit(0).

20.2.4  Time and Date

The current date can be obtained in the form of a UNIX date string:

[eclipse 1]: date(Today).

Today = "Tue May 29 20:49:39 1990\n"

The library calendar contains a utility predicate to convert this string into a Prolog structure. Another way to access the current time and date is the global flag unix_time. It returns the current time in the traditional UNIX measure, i.e., in seconds since 00:00:00 GMT Jan 1, 1970:

[eclipse 1]: get_flag(unix_time, Now).

Now = 644008011

Other interesting timings concern the resource usage of the running ECLiPSe. The statistics/2 built-in gives three different times, the user cpu time, the system cpu time and the elapsed real time since the process was started (all in seconds):

[eclipse 1]: statistics(times, Used).

Used = [0.916667, 1.61667, 2458.88]

The first figure (user cpu time) is the same as given by cputime/1.

20.2.5  Host Computer

Access to the name and unique identification of the host computer where the system is running can be obtained by the two global flags hostname and hostid, accessed via get_flag/2 or env/0. These flags might not be available on all machines, get_flag/2 fails in these cases.

20.2.6  Calling C Functions

Other data may be obtained with the predicate call_c/2 which allows to call directly any C function which is linked to the Prolog system. Functions which are not linked can be loaded dynamically with the load/1 predicate.

Previous Up Next