(ns System "Elixir System module — system-level information and operations. In CljElixir: (System/argv), (System/halt 0), etc.") (defn argv "Returns command line arguments as a list of strings. (System/argv) ;=> [\"--flag\" \"value\"]" []) (defn halt "Halts the Erlang runtime. `status` is 0 (success) or positive integer. (System/halt 0) ;=> exits with code 0 (System/halt 1) ;=> exits with code 1 (System/halt \"crash message\") ;=> prints message and exits" ([]) ([status])) (defn stop "Gracefully stops the system. Runs all shutdown hooks. (System/stop 0)" ([status])) (defn cmd "Runs an external command. Returns {output, exit_status}. (System/cmd \"echo\" [\"hello\"]) ;=> {\"hello\\n\" 0} (System/cmd \"ls\" [\"-la\"] :cd \"/tmp\") ;=> with options" ([command args]) ([command args opts])) (defn shell "Runs a shell command. Returns {output, exit_status}. (System/shell \"echo hello && echo world\") ;=> {\"hello\\nworld\\n\" 0}" ([command]) ([command opts])) (defn get-env "Gets an environment variable. Returns nil if not set. (System/get-env \"HOME\") ;=> \"/Users/ajet\" (System/get-env \"MISSING\" \"default\") ;=> \"default\" (System/get-env) ;=> all env vars as a map" ([]) ([varname]) ([varname default])) (defn put-env "Sets an environment variable. (System/put-env \"MY_VAR\" \"value\") ;=> :ok (System/put-env %{\"KEY1\" \"val1\" \"KEY2\" \"val2\"}) ;=> :ok" ([varname value]) ([env-map])) (defn delete-env "Deletes an environment variable. (System/delete-env \"MY_VAR\") ;=> :ok" [varname]) (defn fetch-env "Fetches an env var. Returns {:ok value} or :error. (System/fetch-env \"HOME\") ;=> {:ok \"/Users/ajet\"}" [varname]) (defn fetch-env! "Fetches an env var. Raises if not set. (System/fetch-env! \"HOME\") ;=> \"/Users/ajet\"" [varname]) (defn cwd "Returns the current working directory. (System/cwd) ;=> \"/Users/ajet/repos/clje\"" []) (defn cwd! "Returns the current working directory. Raises on error." []) (defn tmp-dir "Returns the system temporary directory. (System/tmp-dir) ;=> \"/tmp\"" []) (defn tmp-dir! "Returns the system temporary directory. Raises on error." []) (defn user-home "Returns the user's home directory. (System/user-home) ;=> \"/Users/ajet\"" []) (defn user-home! "Returns the user's home directory. Raises on error." []) (defn monotonic-time "Returns monotonic time. Useful for measuring elapsed time. (System/monotonic-time) ;=> nanoseconds (System/monotonic-time :millisecond) ;=> milliseconds" ([]) ([unit])) (defn system-time "Returns system time (wall clock, not monotonic). (System/system-time) ;=> nanoseconds (System/system-time :second) ;=> seconds since epoch" ([]) ([unit])) (defn os-time "Returns OS time. (System/os-time :second) ;=> seconds since epoch" ([]) ([unit])) (defn unique-integer "Returns a unique integer. (System/unique-integer) ;=> -576460752303423485 (System/unique-integer [:positive :monotonic]) ;=> 1" ([]) ([modifiers])) (defn version "Returns the Elixir version string. (System/version) ;=> \"1.19.5\"" []) (defn otp-release "Returns the OTP release number as a string. (System/otp-release) ;=> \"28\"" []) (defn build-info "Returns a map with build info." []) (defn schedulers "Returns the number of schedulers. (System/schedulers) ;=> 8" []) (defn schedulers-online "Returns the number of online schedulers. (System/schedulers-online) ;=> 8" []) (defn pid "Returns the PID of the OS process running the VM. (System/pid) ;=> \"12345\"" []) (defn at-exit "Registers a function to run at VM exit. (System/at-exit (fn [status] (IO/puts \"bye\")))" [fun]) (defn stacktrace "Returns the last exception stacktrace for the calling process." []) (defn no-halt "Configures whether the system halts on script completion." ([status])) (defn trap-signal "Traps an OS signal. Returns {:ok fun} or {:already-registered fun}. (System/trap-signal :sigterm (fn [] (System/stop 0)))" [signal fun]) (defn untrap-signal "Removes a previously registered signal trap." [signal id]) (defn compiled-endianness "Returns the endianness (:big or :little). (System/compiled-endianness) ;=> :little" [])