OS Module¶
The py.os standard library module provides relational predicates for environment variables, working directory management, and system metadata. For running shell commands and subprocesses, see the Process module.
The implementation lives in clausal/modules/py/os.py.
Import¶
-import_from(py.os, [environment_variable, set_environment_variable,
working_directory, change_directory,
pid, argv, platform, cpu_count])
Or via module import:
Names and values may be passed as strings or atoms. Free-form text the module
hands back (a variable's value, the working directory, each argv entry) is
a string; the platform is a symbolic name and comes back as an atom
(linux), and platform("linux") matches it too ("atom out, text in").
Predicates¶
environment_variable/2¶
environment_variable(Name, Value) — get or enumerate environment variables.
- Name bound: look up the value. Fails if the variable is not set.
- Name unbound: enumerate all environment variables via backtracking.
set_environment_variable/2¶
set_environment_variable(Name, Value) — set an environment variable. Both arguments must be ground strings.
unset_environment_variable/1¶
unset_environment_variable(Name) — remove an environment variable. Fails if the variable is not set.
working_directory/1¶
working_directory(Path) — unify Path with the current working directory.
change_directory/1¶
change_directory(Path) — change the current working directory. Path must be ground. Fails if the path does not exist.
pid/1¶
pid(P) — unify P with the current process ID (integer).
argv/1¶
argv(Args) — unify Args with sys.argv as a list of strings.
platform/1¶
platform(P) — unify P with sys.platform as an atom (e.g. linux, darwin, win32); a bound P may be the atom or the string.
cpu_count/1¶
cpu_count(N) — unify N with the number of CPUs available.