XSB provides a number of facilities for interacting with the UNIX and Windows operating systems. This section describes basic facilities for invoking shell commands and file manipulation. Chapter 1 of Volume 2 discusses more advanced commands for process spawning and control, along with interprocess communication.
For example, the call:
?- shell('echo $HOME').
will output in the current output stream of XSB the name of the user's home directory; while the call:
?- File = 'test.c', shell(['cc -c ', File]).
will call the C compiler to compile the file test.c.
Note that in UNIX systems, since shell/1 is executed by forking off a shell process, it cannot be used, for example, to change the working directory of the interpreter. For that reason the standard predicate cd/1 described below should be used.
`SystemCall`.
In comparison with shell/1 this predicate always succeeds, even if the SystemCall cannot be successfully executed.
Example:
shell_to_list(sw_vers,F,G). F = [[ProductName:,Mac,OS,X],[ProductVersion:,10.4.9],[BuildVersion:,8P2137]] G = 0
Unifies Date to the current date, returned as a Prolog term, suitable for term comparison. Note that datime/1 must be explicitly imported from the module standard.
Example:
> date
Mon Aug 9 16:19:44 EDT 2004
> nxsb1
XSB Version 2.6 (Duff) of June 24, 2003
[i686-pc-cygwin; mode: optimal; engine: slg-wam; gc: indirection; scheduling: local]
| ?- import datime/1 from standard
yes
| ?- datime(F).
F = datime(2004,8,9,20,20,23)
yes