ham-fisted.process
destroy-forcibly!
(destroy-forcibly! proc-hdl)Destroy the process handle's process forcibly.
launch
(launch cmd-line)(launch cmd-line {:keys [stdout-hdlr stderr-hdlr print-cmd-line?], :or {print-cmd-line? true}})Launch a proccess.
- cmd-line string command line.
- stdout-hdrl, stderr-hdlr - transduce-style rf functions that receive each string read from stdout and stderr respectively.
Returns {:keys [^java.lang.ProcessHandle proc-hdl wait-or-kill]}:
proc-hdl- java.lang.ProcessHandlewait-or-kill- function that has two arities:- (proc) - kill the process returning any output as {:out :err}.
- (proc time-ms timeout-symbol) - wait specified time for process to terminate returning either the timeout symbol or {:out :err}.
Example:
ham-fisted.process> (launch "ls -al" {:print-cmd-line? false})
{:proc-hdl #object[java.lang.ProcessHandleImpl 0x7f8e8742 "31019"],
:wait-or-kill #function[ham-fisted.process/launch/wait-or-kill--65545]}
...
ham-fisted.process> (def result ((:wait-or-kill *1)))
#'ham-fisted.process/result
ham-fisted.process> (keys result)
(:out :err)
launch-jvm
(launch-jvm cmd-name {:keys [xmx jvm-opts], :as args})Assumes a jvm process launched from a shell command. Will hang looking for first process descendant.
If shell command then arguments other than :xmx :jvm-opts may need to have quoted strings if they are being passed the clojure process.
Example:
ham-fisted.process> (launch-jvm "clojure" {:jvm-opts ["-A:dev" "-X" "ham-fisted.protocol-perf/-main"]})
launch-process: clojure -A:dev -X ham-fisted.protocol-perf/-main
{:proc-hdl #object[java.lang.ProcessHandleImpl 0x4f4a8dc7 "31194"],
:wait-or-kill #function[ham-fisted.process/launch/wait-or-kill--10016],
:jvm-pid 31199,
:jvm-proc #object[java.lang.ProcessHandleImpl 0x2e52e7c8 "31199"]}
...
ham-fisted.process> (def result ((:wait-or-kill *1)))
#'ham-fisted.process/result
println-rf
Print process output using println. Example process output handler. Returns total output as a string to when finalized.
process-descendants
(process-descendants proc-hdl)Get the first descendants of a process handle.