Go to the first, previous, next, last section, table of contents.


Operating system utilities

Author(s): Daniel Cabeza, Manuel Carro.

Version: 1.5#118 (2000/4/19, 18:13:43 CEST)

Version of last change: 1.3#50 (1999/9/8, 22:35:15 MEST)

This module contains predicates for invoking services which are typically provided by the operating system. Note that the predicates which take names of files or directories as arguments in this module expect atoms, not path aliases. I.e., generally these predicates will not call absolute_file_name/2 on names of files or directories taken as arguments.

Usage and interface (system)

Documentation on exports (system)

PREDICATE: pause/1:

pause(Seconds)

Make this thread sleep for some Seconds.

PREDICATE: time/1:

time(Time)

Time is unified with the number of seconds elapsed since January, 1, 1970 (UTC).

PREDICATE: datime/1:

datime(Datime)

Datime is unified with a term of the form datime(Year,Month,Day,Hour,Minute,Second) which contains the current date and time.

PREDICATE: datime/9:

datime(Time,Year,Month,Day,Hour,Min,Sec,WeekDay,YearDay)

Time is as in time/1. If given, the rest of the arguments are unified with the date and time to which the Time argument refers. If Time is unbound, it is bound to current time and the rest of the arguments refer to current time. WeekDay is the number of days since Sunday, in the range 0 to 6. YearDay is the number of days since January 1, in the range 0 to 365.

REGTYPE: datime_struct/1:

A regular type, defined as follows:


datime_struct(datime(Year,Month,Day,Hour,Min,Sec)) :-
        int(Year),
        int(Month),
        int(Day),
        int(Hour),
        int(Min),
        int(Sec).

PREDICATE: getenvstr/2:

getenvstr(Name,Value)

The environment variable Name has Value. Fails if variable Name is not defined.

PREDICATE: extract_paths/2:

extract_paths(String,Paths)

Interpret String as the value of a UNIX environment variable holding a list of paths and return in Paths the list of the paths. Paths in String are separated by colons, and an empty path is considered a shorthand for '.' (current path). The most typical environment variable with this format is PATH. For example, this is a typical use:

?- set_prolog_flag(write_strings, on).

yes
?- getenvstr('PATH', PATH), extract_paths(PATH, Paths).

PATH = ":/home/bardo/bin:/home/clip/bin:/opt/bin/:/bin",
Paths = [".","/home/bardo/bin","/home/clip/bin","/opt/bin/","/bin"] ?

yes
?- 

PREDICATE: get_pid/1:

get_pid(Pid)

Unifies Pid with the process identificator of the current process or thread.

PREDICATE: current_host/1:

current_host(Hostname)

Hostname is unified with the fully qualified name of the host.

PREDICATE: current_executable/1:

current_executable(Path)

Unifies Path with the path to the current executable.

PREDICATE: umask/2:

umask(OldMask,NewMask)

The process file creation mask was OldMask, and it is changed to NewMask.

Usage 2: umask(OldMask,NewMask)

PREDICATE: working_directory/2:

working_directory(OldDir,NewDir)

Unifies current working directory with OldDir, and then changes the working directory to NewDir. Calling working_directory(Dir,Dir) simply unifies Dir with the current working directory without changing anything else.

Usage 2: working_directory(OldDir,NewDir)

PREDICATE: cd/1:

cd(Path)

Changes working directory to Path.

PREDICATE: shell/0:

Usage:

PREDICATE: shell/1:

shell(Command)

Command is executed in the shell specified by the environment variable SHELL. It succeeds if the exit code is zero and fails otherwise.

PREDICATE: shell/2:

shell(Command,ReturnCode)

Executes Command in the shell specified by the environment variable SHELL and stores the exit code in ReturnCode.

PREDICATE: system/1:

system(Command)

Executes Command using the shell /bin/sh.

PREDICATE: system/2:

system(Command,ReturnCode)

Executes Command in the /bin/sh shell and stores the exit code in ReturnCode.

PREDICATE: popen/3:

popen(Command,Mode,Stream)

Open a pipe to process Command in a new shell with a given Mode and return a communication Stream (as in UNIX popen(3)). If Mode is read the output from the process is sent to Stream. If Mode is write, Stream is sent as input to the process. Stream may be read from or written into using the ordinary stream I/O predicates. Stream must be closed explicitly using close/1, i.e., it is not closed automatically when the process dies.

REGTYPE: popen_mode/1:

Usage: popen_mode(M)

PREDICATE: exec/4:

exec(Command,StdIn,StdOut,StdErr)

Starts the process Command and returns the I/O streams of the process in StdIn, StdOut, and StdErr.

PREDICATE: exec/3:

exec(Command,StdIn,StdOut)

Starts the process Command and returns the I/O streams of the process in StdIn and StdOut. Standard error is connected to whichever the parent process had it connected to.

PREDICATE: directory_files/2:

directory_files(Directory,FileList)

FileList is the unordered list of entries (files, directories, etc.) in Directory.

PREDICATE: mktemp/2:

mktemp(Template,Filename)

Returns a unique Filename based on Template: Template must be a valid file name with six trailing X, which are substituted to create a new file name.

PREDICATE: file_exists/1:

file_exists(File)

Succeeds if File (a file or directory) exists (and is accessible).

PREDICATE: file_exists/2:

file_exists(File,Mode)

File (a file or directory) exists and it is accessible with Mode, as in the Unix call access(2). Typically, Mode is 4 for read permission, 2 for write permission and 1 for execute permission.

PREDICATE: file_property/2:

file_property(File,Property)

File has the property Property. The possible properties are:

type(Type)
Type is one of regular, directory, symlink, fifo, socket or unknown.
linkto(Linkto)
If File is a symbolic link, Linkto is the file pointed to by the link (and the other properties come from that file, not from the link itself).
mod_time(ModTime)
ModTime is the time of last modification (seconds since January, 1, 1970).
mode(Protection)
Protection is the protection mode.
size(Size)
Size is the size.

If Property is uninstantiated, the predicate will enumerate the properties on backtracking.

PREDICATE: file_properties/6:

file_properties(Path,Type,Linkto,Time,Protection,Size)

The file Path has the following properties:

PREDICATE: modif_time/2:

modif_time(File,Time)

The file File was last modified at Time, which is in seconds since January, 1, 1970. Fails if File does not exist.

PREDICATE: modif_time0/2:

modif_time0(File,Time)

If File exists, Time is its latest modification time, as in modif_time/2. Otherwise, if File does not exist, Time is zero.

PREDICATE: fmode/2:

fmode(File,Mode)

The file File has protection mode Mode.

PREDICATE: chmod/2:

chmod(File,NewMode)

Change the protection mode of file File to NewMode.

PREDICATE: chmod/3:

chmod(File,OldMode,NewMode)

The file File has protection mode OldMode and it is changed to NewMode.

Usage 2: chmod(File,OldMode,NewMode)

PREDICATE: delete_file/1:

delete_file(File)

Delete the file File.


Go to the first, previous, next, last section, table of contents.