JanetDocsPlaygroundI'm feeling luckyGitHub sign in

os/spawn



    cfunction
    src/core/os.c on line 1117, column 1

    (os/spawn args &opt flags env)

    Execute a program on the system and return a handle to the process. 
    Otherwise, takes the same arguments as `os/execute`. Does not wait 
    for the process. For each of the :in, :out, and :err keys to the 
    `env` argument, one can also pass in the keyword `:pipe` to get 
    streams for standard IO of the subprocess that can be read from and 
    written to. The returned value `proc` has the fields :in, :out, 
    :err, :return-code, and the additional field :pid on unix-like 
    platforms. Use `(os/proc-wait proc)` to rejoin the subprocess or 
    `(os/proc-kill proc)`.


2 examplesSign in to add an example
Loading...
(def p (os/spawn ["ls"] :p {:in :pipe :out :pipe})) # define core/process with selfpipe
(pp (:read (p :out) :all)) # => prints the ls output
(pp (:wait p)) # => waits for the process to finish, prints 0 if succesful 
pepePlayground
(def p1 (os/spawn ["echo" "hello"] :p {:out :pipe}))
(def p2 (os/spawn ["grep" "hello"] :p {:in (p1 :out)}))

(:wait p2)
# Creates a pipeline (e.g. echo hello | grep hello)
bakpakinPlayground