概要
paiza.ioでelixirやってみた。
System使ってみた。
サンプルコード
prev = System.os_time()
next = System.os_time()
diff = next - prev
IO.puts diff
prev = System.monotonic_time()
next = System.monotonic_time()
diff = next - prev
IO.puts diff
System.build_info()
|> IO.inspect
System.cmd("echo", ["hello"])
|> IO.inspect
System.cmd("echo", ["hello"], env: [{"MIX_ENV", "test"}])
|> IO.inspect
System.cmd("echo", ["hello"], into: IO.stream())
|> IO.inspect
System.fetch_env("PORT")
|> IO.inspect
System.fetch_env("NOT_SET")
|> IO.inspect
#System.fetch_env!("PORT")
System.get_env("PORT")
|> IO.inspect
#System.halt(0)
#System.halt(1)
System.pid()
|> IO.inspect
System.tmp_dir()
|> IO.inspect
#System.restart()
System.shell("echo hello")
|> IO.inspect
#System.stop(0)
#System.stop(1)
System.user_home()
|> IO.inspect
System.version()
|> IO.inspect
実行結果
408
159
%{
build: "1.12.3 (compiled with Erlang/OTP 22)",
date: "2022-09-01T08:25:44Z",
otp_release: "22",
revision: "a64d42f",
version: "1.12.3"
}
{"hello\n", 0}
{"hello\n", 0}
hello
{%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: false}, 0}
:error
:error
nil
"11"
"/tmp"
{"hello\n", 0}
"/workspace"
"1.12.3"
成果物
以上。