YAP 7.1.0
Operating System Functionality

Portable Interaction with the OS, be it Unix, Linux, OSX, or Windows. More...

Detailed Description

Portable Interaction with the OS, be it Unix, Linux, OSX, or Windows.

YAP provides a library of system utilities compatible with the SICStus Prolog system library This library extends and to some point complements the functionality of Operating System access routines The library includes Unix/Linux and Win32 C code They are available through the use_module(library(system)) command


Class Documentation

◆ file_property/2

class file_property/2

file_property(+ File,? Property)

The atom File corresponds to an existing file, and Property will be unified with a property of this file The properties are of the form type( _Type_), which gives whether the file is a regular file, a directory, a fifo file, or of unknown type; size( _Size_), with gives the size for a file, and mod_time( _Time_), which gives the last time a file was modified according to some Operating System dependent timestamp; mode( _mode_), gives the permission flags for the file, and linkto( _FileName_), gives the file pointed to by a symbolic link Properties can be obtained through backtracking:

?- file_property('Makefile',P).
P = type(regular) ? ;
P = size(2375) ? ;
P = mod_time(990826911) ? ;
mod_time
file_property(+ File,? Property)

◆ host_id/1

class host_id/1

host_id(- Id)

7
Unify Id with an identifier of the current host YAP uses the hostid function when available,

◆ host_name/1

class host_name/1

host_name(- Name)

Unify Name with a name for the current host YAP uses the hostname function in Unix systems when available, and the GetComputerName function in WIN32 systems

◆ mktemp/2

class mktemp/2

mktemp( Spec,- File)

Direct interface to mktemp: given a Spec, that is a file name with six X to it, create a file name File Use tmpnam/1 instead

◆ mktime/2

class mktime/2

mktime(+_Datime_, - Seconds)

The mktime/2 procedure receives a term of the form datime(+ _Year,

  • Month, + DayOfTheMonth, + Hour, + Minute, + Second)_ and returns the number of Seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) The user provides information on Year, Month, DayOfTheMonth, Hour, Minute, and Second The Hour is given on local time This function uses the WIN32 GetLocalTime function or the Unix mktime function
?- mktime(datime(2001,5,28,15,29,46),X).
X = 991081786 ? ;
mktime(+_Datime_, - Seconds)

◆ pid/1

class pid/1

pid(- Id)

Unify Id with the process identifier for the current process An interface to the getpid function

◆ read_link/3

class read_link/3

read_link(+ SymbolicLink, -Link, -NewPath)

Follow a SymbolicLink, and obtain the actual Link and the target newPath) This predicate uses the C built-in function readlink and is not yet operational in WIN32

◆ shell/1

class shell/1

shell(+ Command)

Execute command Command under a new shell YAP will be in background until the command completes In Unix environments YAP uses the shell given by the environment variable SHELL with the option " -c " In WIN32 environment YAP will use COMSPEC if SHELL is undefined, in this case with the option " /c "

◆ shell/2

class shell/2

shell(+ Command,- Status)

Execute command Command under a new shell and unify Status with the exit for the command YAP will be in background until the command completes In Unix environments YAP uses the shell given by the environment variable SHELL with the option " -c " In WIN32 environment YAP will use COMSPEC if SHELL is undefined, in this case with the option " /c "

◆ tmp_file/2

class tmp_file/2

tmp_file(+_Base_, - File)

Create a name for a temporary file Base is an user provided identifier for the category of file The TmpName is guaranteed to be unique If the system halts, it will automatically remove all created temporary files

◆ tmpnam/1

class tmpnam/1

tmpnam(- File)

7

Interface with tmpnam: obtain a new, unique file name File

◆ datime/6

class datime/6

datime(datime(- Year, - Month, - DayOfTheMonth, - Hour, - Minute, - Second)

The datime/1 procedure returns the current date and time, with information on Year, Month, DayOfTheMonth, Hour, Minute, and Second The Hour is returned on local time This function uses the WIN32 GetLocalTime function or the Unix localtime function

?- datime(X).
X = datime(2001,5,28,15,29,46) ?
datime(datime(- Year, - Month, - DayOfTheMonth, - Hour, - Minute, - Second)

◆ delete_file/2

class delete_file/2

delete_file(+ File,+ Opts)

The delete_file/2 procedure removes file File according to options Opts These options are directory if one should remove directories, recursive if one should remove directories recursively, and ignore if errors are not to be reported

This example is equivalent to using the delete_file/1 predicate:

?- delete_file(x, [recursive]).
delete_file(+ File,+ Opts)

◆ environ/2

class environ/2

environ(? EnvVar,+ EnvValue)

Unify environment variable EnvVar with its value EnvValue, if there is one This predicate is backtrackable in Unix systems, but not currently in Win32 configurations

?- environ('HOME',V).
V = 'C:\\cygwin\\home\\administrator' ?
environ(? EnvVar,+ EnvValue)

EnvVar may be bound to an atom, or just be unbound In the latter case environ/2 will enumerate over all environment variables

◆ exec/3

class exec/3

exec(+ Command, StandardStreams, -PID)

  • Execute command Command with its standard streams connected to the list [InputStream, OutputStream, ErrorStream] A numeric identifier to the process that executes the command is returned as PID The command is executed by the default shell bin/sh -c in Unix
  • The following example demonstrates the use of exec/3 to send a command and process its output:
  • :-
    exec(ls,[std,pipe(S),null],P),
    exec,
    get0(S,C),
    (C = -1, close(S) close ; put(C)).
    close(+ S)
    exec(+ Command, StandardStreams, -PID)
  • The streams may be one of standard stream, std, null stream, null, or pipe(S), where S is a pipe stream Note that it is up to the user to close the pipe

◆ popen/3

class popen/3

popen( +Command, +TYPE, -Stream)

Provides the functionaluty of the Unix popen function It opens a process by creating a pipe, forking and invoking Command on a * the child process Since a pipe is by definition unidirectional the Type argument may be read or write, not both The stream should be closed using close/1 , there is no need for a special pclose command

  • The following example demonstrates the use of popen/3 to process the output of a command, note that popen/3 works as a simplified interface to the exec/3 command:
  • ?- popen(ls,read,X),popen, get0(X,C), (C = -1, ! ; put(C)).
    X = 'C:\\cygwin\\home\\administrator' ?
    popen( +Command, +TYPE, -Stream)
  • The implementation of popen/3 relies on exec/3

◆ system/1

class system/1

system(+ S)

Passes command S to the Bourne shell (on UNIX environments) or the current command interpreter in WIN32 environments

Passes command S to the Bourne shell (on UNIX environments) or the current command interpreter in WIN32 environments

Note that it executes them command as a detached process It requires system to be implemented by the system library

Definition at line 2 of file system.yap.

◆ system/2

class system/2

system(+ Command,- Res)

Interface to system: execute command Command and unify Res with the result

n

◆ rename_file/2

class rename_file/2

rename_file(+ OldFile,+ NewFile)

Create file OldFile to NewFile This predicate uses the C built-in function rename

◆ directory_files/2

class directory_files/2

directory_files(+ Dir,+ List)

directory_files(+-_Dir_,-_List of Files)

Given a directory Dir, directory_files/2 procedures a listing of all fniles and directories in the directory:

?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
directory_files(+ Dir,+ List)

The predicates uses the dirent family of routines in Unix environments, and findfirst in WIN32 through the system_library buil

)

  • If Dir is S valid path to an existing directory, and the current process holds the necessary permission ListOfFiles will be unified with all the files in directory The list of files is not guaranteed to follow any specific order
  • This built-in is just a stub for list_directory/2 It is exported from the user module and from the system library

◆ directory_map/2

class directory_map/2

directory_map(+ Dir, 1:P)

Given a directory Dir, directory_map/2 visits all files in Dir, and verifies whether P(F) holds, where F is the file's absolute path

?- directory_map('.', process).
directory_map(+ Dir, 1:P)

The predicates performs a left-recursive traversal It does not protect against file system errors and it does not check for symbolic links