JanetDocsPlaygroundI'm feeling luckyGitHub sign in

os/execute



    cfunction

    (os/execute args &opt flags env)

    Execute a program on the system and pass it string arguments. 
    `flags` is a keyword that modifies how the program will execute.

    * :e - enables passing an environment to the program. Without :e, 
      the current environment is inherited.

    * :p - allows searching the current PATH for the binary to execute. 
      Without this flag, binaries must use absolute paths.

    * :x - raise error if exit code is non-zero.

    `env` is a table or struct mapping environment variables to values. 
    It can also contain the keys :in, :out, and :err, which allow 
    redirecting stdio in the subprocess. These arguments should be 
    core/file values. One can also pass in the :pipe keyword for these 
    arguments to create files that will read (for :err and :out) or 
    write (for :in) to the file descriptor of the subprocess. This is 
    only useful in `os/spawn`, which takes the same parameters as 
    `os/execute`, but will return an object that contains references to 
    these files via (return-value :in), (return-value :out), and 
    (return-value :err). Returns the exit status of the program.


2 examplesSign in to add an example
Loading...
(os/execute
  @("/usr/bin/bash" "-c" "set")
  :e
  @{"SOME" "value"
    "OTHER" "one"})
# => 0

# execute bash and prints environment variables
# which contains SOME=value and Other=one
goldenHairDafoPlayground
(os/execute
  @("python" "-c" "print('Hello Janet'"))
  :p) 
# => 0

# execute python -c "print('Hello Janet') while
# searching path on the current path
goldenHairDafoPlayground