Author(s): Daniel Cabeza, Manuel Carro.
Version: 1.11#222 (2004/5/24, 13:8:7 CEST)
Version of last change: 1.11#184 (2004/2/11, 18:35:28 CET)
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.
system):- use_module(library(system)).
pause/1,
time/1,
datime/1,
datime/9,
getenvstr/2,
setenvstr/2,
current_env/2,
set_env/2,
del_env/1,
copy_file/2,
extract_paths/2,
get_pid/1,
current_host/1,
current_executable/1,
umask/2,
make_directory/2,
make_directory/1,
make_dirpath/2,
make_dirpath/1,
working_directory/2,
cd/1,
shell/0,
shell/1,
shell/2,
system/1,
system/2,
popen/3,
exec/4,
exec/3,
directory_files/2,
mktemp/2,
file_exists/1,
file_exists/2,
file_property/2,
file_properties/6,
modif_time/2,
modif_time0/2,
fmode/2,
chmod/2,
chmod/3,
delete_file/1,
delete_directory/1,
rename_file/2,
cyg2win/3.
datime_struct/1,
popen_mode/1.
define_flag/3.
system)
pause(Seconds)
Make this thread sleep for some Seconds.
Usage:
Seconds is an integer.
(basic_props:int/1)
time(Time)
Time is unified with the number of seconds elapsed since January, 1, 1970 (UTC).
Usage:
Time is an integer.
(basic_props:int/1)
Time is an integer.
(basic_props:int/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.
Usage:
system:datime_struct(Datime)
(system:datime_struct/1)
system:datime_struct(Datime)
(system:datime_struct/1)
datime(Time, Year, Month, Day, Hour, Min, Sec, WeekDay, YearDay)
Time is as in
time/1. 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.
Usage 1:
Time is given, the rest of the arguments are unified with the date and time to which the Time argument refers.
Year is an integer.
(basic_props:int/1)
Month is an integer.
(basic_props:int/1)
Day is an integer.
(basic_props:int/1)
Hour is an integer.
(basic_props:int/1)
Min is an integer.
(basic_props:int/1)
Sec is an integer.
(basic_props:int/1)
WeekDay is an integer.
(basic_props:int/1)
YearDay is an integer.
(basic_props:int/1)
Time is an integer.
(basic_props:int/1)
Year is an integer.
(basic_props:int/1)
Month is an integer.
(basic_props:int/1)
Day is an integer.
(basic_props:int/1)
Hour is an integer.
(basic_props:int/1)
Min is an integer.
(basic_props:int/1)
Sec is an integer.
(basic_props:int/1)
WeekDay is an integer.
(basic_props:int/1)
YearDay is an integer.
(basic_props:int/1)
Usage 2:
Time to current time and the rest of the arguments refer to current time.
Year is an integer.
(basic_props:int/1)
Month is an integer.
(basic_props:int/1)
Day is an integer.
(basic_props:int/1)
Hour is an integer.
(basic_props:int/1)
Min is an integer.
(basic_props:int/1)
Sec is an integer.
(basic_props:int/1)
WeekDay is an integer.
(basic_props:int/1)
YearDay is an integer.
(basic_props:int/1)
Time is a free variable.
(term_typing:var/1)
Time is an integer.
(basic_props:int/1)
Year is an integer.
(basic_props:int/1)
Month is an integer.
(basic_props:int/1)
Day is an integer.
(basic_props:int/1)
Hour is an integer.
(basic_props:int/1)
Min is an integer.
(basic_props:int/1)
Sec is an integer.
(basic_props:int/1)
WeekDay is an integer.
(basic_props:int/1)
YearDay is an integer.
(basic_props:int/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).
getenvstr(Name, Value)
The environment variable Name has Value. Fails if variable Name is not defined.
Usage:
Value is a string (a list of character codes).
(basic_props:string/1)
Name is an atom.
(basic_props:atm/1)
Value is a string (a list of character codes).
(basic_props:string/1)
setenvstr(Name, Value)
The environment variable Name is assigned Value.
Usage:
Name is an atom.
(basic_props:atm/1)
Value is a string (a list of character codes).
(basic_props:string/1)
current_env(Name, Value)
If Name is an atom, then unifies the environment variable Name with its value. Note that this predicate can be used to enumerate all the environment variables using backtracking.
Usage:
Name is an atom.
(basic_props:atm/1)
Value is an atom.
(basic_props:atm/1)
Name is an atom.
(basic_props:atm/1)
Value is an atom.
(basic_props:atm/1)
set_env(Name, Value)
The environment variable Name is assigned Value.
Usage:
Name is an atom.
(basic_props:atm/1)
Value is an atom.
(basic_props:atm/1)
del_env(Name)
The environment variable Name is removed.
Usage:
Name is an atom.
(basic_props:atm/1)
copy_file(Source, Destination)
Copies the file {Source
Usage:
Source is an atom.
(basic_props:atm/1)
Destination is an atom.
(basic_props:atm/1)
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
?-
Usage:
Paths is a list of strings.
(basic_props:list/2)
String is a string (a list of character codes).
(basic_props:string/1)
Paths is a list of strings.
(basic_props:list/2)
get_pid(Pid)
Unifies Pid with the process identificator of the current process or thread.
Usage:
Pid is an integer.
(basic_props:int/1)
Pid is an integer.
(basic_props:int/1)
current_host(Hostname)
Hostname is unified with the fully qualified name of the host.
Usage:
Hostname is an atom.
(basic_props:atm/1)
Hostname is an atom.
(basic_props:atm/1)
current_executable(Path)
Unifies Path with the path to the current executable.
Usage:
Path is an atom.
(basic_props:atm/1)
Path is an atom.
(basic_props:atm/1)
umask(OldMask, NewMask)
The process file creation mask was OldMask, and it is changed to NewMask.
Usage 1:
OldMask is an integer.
(basic_props:int/1)
NewMask is an integer.
(basic_props:int/1)
OldMask is an integer.
(basic_props:int/1)
Usage 2: umask(OldMask, NewMask)
OldMask is a free variable.
(term_typing:var/1)
NewMask is a free variable.
(term_typing:var/1)
The terms OldMask and NewMask are strictly identical.
(term_compare:== /2)
OldMask is an integer.
(basic_props:int/1)
NewMask is an integer.
(basic_props:int/1)
make_directory(DirName, Mode)
Creates the directory DirName with a given Mode. This is, as usual, operated against the current umask value.
Usage:
DirName is an atom.
(basic_props:atm/1)
Mode is an integer.
(basic_props:int/1)
make_directory(DirName)
Equivalent to make_directory(D,0o777).
Usage:
DirName is an atom.
(basic_props:atm/1)
make_dirpath(Path, Mode)
Creates the whole Path for a given directory with a given Mode. As an example, make_dirpath('/tmp/var/mydir/otherdir').
Usage:
Path is a source name.
(streams_basic:sourcename/1)
Mode is an integer.
(basic_props:int/1)
make_dirpath(Path)
Equivalent to make_dirpath(D,0o777).
Usage 1:
Path is an atom.
(basic_props:atm/1)
Usage 2:
Path is an atom.
(basic_props:atm/1)
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 1:
OldDir is an atom.
(basic_props:atm/1)
NewDir is an atom.
(basic_props:atm/1)
OldDir is an atom.
(basic_props:atm/1)
Usage 2: working_directory(OldDir, NewDir)
OldDir is a free variable.
(term_typing:var/1)
NewDir is a free variable.
(term_typing:var/1)
The terms OldDir and NewDir are strictly identical.
(term_compare:== /2)
OldDir is an atom.
(basic_props:atm/1)
NewDir is an atom.
(basic_props:atm/1)
cd(Path)
Changes working directory to Path.
Usage:
Path is an atom.
(basic_props:atm/1)
Usage:
SHELL. When the shell process terminates, control is returned to Prolog.
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.
Usage:
Command is an atom.
(basic_props:atm/1)
shell(Command, ReturnCode)
Executes Command in the shell specified by the environment variable SHELL and stores the exit code in ReturnCode.
Usage:
ReturnCode is an integer.
(basic_props:int/1)
Command is an atom.
(basic_props:atm/1)
ReturnCode is an integer.
(basic_props:int/1)
system(Command)
Executes Command using the shell
/bin/sh.
Usage:
Command is an atom.
(basic_props:atm/1)
system(Command, ReturnCode)
Executes Command in the
/bin/sh shell and stores the exit code in ReturnCode.
Usage:
ReturnCode is an integer.
(basic_props:int/1)
Command is an atom.
(basic_props:atm/1)
ReturnCode is an integer.
(basic_props:int/1)
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.
Usage:
Command is an atom.
(basic_props:atm/1)
Mode is 'read' or 'write'.
(system:popen_mode/1)
Stream is a free variable.
(term_typing:var/1)
Stream is an open stream.
(streams_basic:stream/1)
Usage: popen_mode(M)
M is 'read' or 'write'.
exec(Command, StdIn, StdOut, StdErr)
Starts the process Command and returns the standart I/O streams of the process in StdIn, StdOut, and StdErr.
Usage:
Command is an atom.
(basic_props:atm/1)
StdIn is a free variable.
(term_typing:var/1)
StdOut is a free variable.
(term_typing:var/1)
StdErr is a free variable.
(term_typing:var/1)
StdIn is an open stream.
(streams_basic:stream/1)
StdOut is an open stream.
(streams_basic:stream/1)
StdErr is an open stream.
(streams_basic:stream/1)
exec(Command, StdIn, StdOut)
Starts the process Command and returns the standart I/O streams of the process in StdIn and StdOut. Standard error is connected to whichever the parent process had it connected to.
Usage:
Command is an atom.
(basic_props:atm/1)
StdIn is a free variable.
(term_typing:var/1)
StdOut is a free variable.
(term_typing:var/1)
StdIn is an open stream.
(streams_basic:stream/1)
StdOut is an open stream.
(streams_basic:stream/1)
directory_files(Directory, FileList)
FileList is the unordered list of entries (files, directories, etc.) in Directory.
Usage:
FileList is a list of atms.
(basic_props:list/2)
Directory is an atom.
(basic_props:atm/1)
FileList is a list of atms.
(basic_props:list/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.
Usage:
Filename is an atom.
(basic_props:atm/1)
Template is an atom.
(basic_props:atm/1)
Filename is an atom.
(basic_props:atm/1)
file_exists(File)
Succeeds if File (a file or directory) exists (and is accessible).
Usage:
File is an atom.
(basic_props:atm/1)
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.
Usage:
File is an atom.
(basic_props:atm/1)
Mode is an integer.
(basic_props:int/1)
file_property(File, Property)
File has the property Property. The possible properties are:
Type)
Type is one of regular, directory, symlink, fifo, socket or unknown.
Linkto)
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).
ModTime)
ModTime is the time of last modification (seconds since January, 1, 1970).
Protection)
Protection is the protection mode.
Size)
Size is the size.
If Property is uninstantiated, the predicate will enumerate the properties on backtracking.
Usage:
Property is a compound term.
(basic_props:struct/1)
File is an atom.
(basic_props:atm/1)
Property is a compound term.
(basic_props:struct/1)
file_properties(Path, Type, Linkto, Time, Protection, Size)
The file Path has the following properties:
Type (one of regular, directory, symlink, fifo, socket or unknown).
Path is a symbolic link, Linkto is the file pointed to. All other properties come from the file pointed, not the link. Linkto is " if Path is not a symbolic link.
Time (seconds since January, 1, 1970).
Protection.
Size.
Usage:
Type is an atom.
(basic_props:atm/1)
Linkto is an atom.
(basic_props:atm/1)
Time is an integer.
(basic_props:int/1)
Protection is an integer.
(basic_props:int/1)
Size is an integer.
(basic_props:int/1)
Path is an atom.
(basic_props:atm/1)
Type is an atom.
(basic_props:atm/1)
Linkto is an atom.
(basic_props:atm/1)
Time is an integer.
(basic_props:int/1)
Protection is an integer.
(basic_props:int/1)
Size is an integer.
(basic_props:int/1)
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.
Usage:
Time is an integer.
(basic_props:int/1)
File is an atom.
(basic_props:atm/1)
Time is an integer.
(basic_props:int/1)
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.
Usage:
Time is an integer.
(basic_props:int/1)
File is an atom.
(basic_props:atm/1)
Time is an integer.
(basic_props:int/1)
fmode(File, Mode)
The file File has protection mode Mode.
Usage:
Mode is an integer.
(basic_props:int/1)
File is an atom.
(basic_props:atm/1)
Mode is an integer.
(basic_props:int/1)
chmod(File, NewMode)
Change the protection mode of file File to NewMode.
Usage:
File is an atom.
(basic_props:atm/1)
NewMode is an integer.
(basic_props:int/1)
chmod(File, OldMode, NewMode)
The file File has protection mode OldMode and it is changed to NewMode.
Usage 1:
OldMode is an integer.
(basic_props:int/1)
File is an atom.
(basic_props:atm/1)
NewMode is an integer.
(basic_props:int/1)
OldMode is an integer.
(basic_props:int/1)
Usage 2: chmod(File, OldMode, NewMode)
File,OldMode)
File is an atom.
(basic_props:atm/1)
OldMode is a free variable.
(term_typing:var/1)
NewMode is a free variable.
(term_typing:var/1)
The terms OldMode and NewMode are strictly identical.
(term_compare:== /2)
File is an atom.
(basic_props:atm/1)
OldMode is an atom.
(basic_props:atm/1)
NewMode is an atom.
(basic_props:atm/1)
delete_file(File)
Delete the file File.
Usage:
File is an atom.
(basic_props:atm/1)
delete_directory(File)
Delete the directory Directory.
Usage:
File is an atom.
(basic_props:atm/1)
rename_file(File1, File2)
Change the name of File1 to File2.
Usage:
File1 is an atom.
(basic_props:atm/1)
File2 is an atom.
(basic_props:atm/1)
Usage: cyg2win(CygWinPath, WindowsPath, SpawSlash)
SwapSlash is swap, slashes are converted in to backslash. If it is noswap, they are preserved.
CygWinPath is a string (a list of character codes).
(basic_props:string/1)
WindowsPath is a free variable.
(term_typing:var/1)
SpawSlash is currently instantiated to an atom.
(term_typing:atom/1)
CygWinPath is a string (a list of character codes).
(basic_props:string/1)
WindowsPath is a string (a list of character codes).
(basic_props:string/1)
SpawSlash is currently instantiated to an atom.
(term_typing:atom/1)
system)No further documentation available for this predicate.
The predicate is multifile.
system)shell/n commands have a bug in Windows: if the environment variable SHELL is instantiated to some Windows shell implementation, then it is very possible that shell/
exec/4 does not find the command to be executed, there is no visible error message: it is sent to a error output which has already been assigned to a different stream, disconnected from the one the user sees.
Go to the first, previous, next, last section, table of contents.