Files
2026-03-09 23:09:46 -04:00

50 lines
1.1 KiB
Clojure

(ns Port
"Elixir Port module — external program interaction.
In CljElixir: (Port/open {:spawn \"cmd\"} opts), etc.
Ports allow communication with external OS processes via stdin/stdout.")
(defn open
"Opens a port to an external program. Returns a port.
(Port/open {:spawn \"cat\"} [:binary])
(Port/open {:spawn-executable \"/usr/bin/python3\"} [:binary {:args [\"-c\" \"print(1)\"]}])
(Port/open {:fd 0 1} [:binary]) ;=> stdin/stdout"
[name settings])
(defn command
"Sends data to a port.
(Port/command port data)"
([port data])
([port data opts]))
(defn close
"Closes a port.
(Port/close port) ;=> true"
[port])
(defn connect
"Changes the owner of a port.
(Port/connect port new-owner-pid)"
[port pid])
(defn info
"Returns information about a port.
(Port/info port) ;=> [{:name ...} {:links [...]} ...]
(Port/info port :name) ;=> port name"
([port])
([port item]))
(defn list
"Returns all open ports.
(Port/list) ;=> [#Port<0.5> ...]"
[])
(defn monitor
"Monitors a port. Returns reference."
[type port])
(defn demonitor
"Stops monitoring a port."
([ref])
([ref opts]))