Module os
:- use_module(library(os)).
Predicates for reasoning about the operating system (OS) environment.
This includes predicates about environment variables, calls to shell and finding out the PID of the running system.
getenv(+Key, -Value).
True iff Value contains the value of the environment variable Key. Example:
?- getenv("LANG", Ls).
Ls = "en_US.UTF-8".
setenv(+Key, +Value).
Sets the environment variable Key to Value
unsetenv(+Key).
Unsets the environment variable Key
shell(+Command)
Equivalent to shell(Command, 0)
.
shell(+Command, -Status).
True iff executes Command in a shell of the operating system and the exit code is Status. Keep in mind the shell syntax is dependant on the operating system, so it should be used very carefully.
Example (using Linux and fish shell):
?- shell("echo $SHELL", Status).
/bin/fish
Status = 0.
pid(-PID).
True iff PID is the process identification number of current Scryer Prolog instance.
raw_argv(-Argv)
True iff Argv is the list of arguments that this program was started with (usually passed via command line). In contrast to argv/1
, this version includes every argument, without any postprocessing, just as the operating system reports it to the system. This includes-flags of Scryer itself, which are not needed in general.
argv(-Argv)
True if Argv is the list of arguments that this program was started with (usually passed via command line). In this version, only arguments specific to the program are passed. To differentiate between the system arguments and the program arguments, we use --
as a separator.
Example:
% Call with scryer-prolog -f -- -t hello
?- argv(X).
X = ["-t", "hello"].