JanetDocsSourcePlaygroundI'm feeling luckyCommunityGitHub sign in

os/spawn

core-api


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

    (os/spawn args &opt flags env)

    Execute a program on the system and return a core/process value 
    representing the spawned subprocess. Takes the same arguments as 
    `os/execute` but does not wait for the subprocess to complete. 
    Unlike `os/execute`, the value `:pipe` can be used for :in, :out 
    and :err keys in `env`. If used, the returned core/process will 
    have a writable stream in the :in field and readable streams in the 
    :out and :err fields. On non-Windows systems, the subprocess PID 
    will be in the :pid field. The caller is responsible for waiting on 
    the process (e.g. by calling `os/proc-wait` on the returned 
    core/process value) to avoid creating zombie process. After the 
    subprocess completes, the exit value is in the :return-code field. 
    If `flags` includes 'x', a non-zero exit code will cause a waiting 
    fiber to raise an error. The use of `:pipe` may fail if there are 
    too many active file descriptors. The caller is responsible for 
    closing pipes created by `:pipe` (either individually or using 
    `os/proc-close`). Similar to `os/execute`, the caller is 
    responsible for ensuring pipes do not cause the program to block 
    and deadlock.


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