![]() |
YAP 7.1.0
|
Portable Interaction with the OS, be it Unix, Linux, OSX, or Windows. More...
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 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:
class host_id/1 |
host_id(- Id)
7
Unify Id with an identifier of the current host YAP uses the hostid
function when available,
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
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
class mktime/2 |
mktime(+_Datime_, - Seconds)
The mktime/2
procedure receives a term of the form datime(+ _Year,
GetLocalTime
function or the Unix mktime
functionclass pid/1 |
pid(- Id)
Unify Id with the process identifier for the current process An interface to the getpid
function
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
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 "
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 "
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
class tmpnam/1 |
tmpnam(- File)
7
Interface with tmpnam: obtain a new, unique file name File
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
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:
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
EnvVar may be bound to an atom, or just be unbound In the latter case environ/2 will enumerate over all environment variables
class exec/3 |
exec(+ Command, StandardStreams, -PID)
bin/sh -c
in Unixstd
, null stream, null
, or pipe(S)
, where S is a pipe stream Note that it is up to the user to close the pipeclass 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
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.
class system/2 |
system(+ Command,- Res)
Interface to system
: execute command Command and unify Res with the result
n
class rename_file/2 |
rename_file(+ OldFile,+ NewFile)
Create file OldFile to NewFile This predicate uses the C
built-in function rename
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:
The predicates uses the dirent
family of routines in Unix environments, and findfirst
in WIN32 through the system_library buil
)
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
The predicates performs a left-recursive traversal It does not protect against file system errors and it does not check for symbolic links