Ink by Example — Execing Processes

Ink by Example: Execing Processes

Ink can spawn child processes. The stdout data is passed to a callback when the process ends.

std := load('../vendor/std')
each := std.each
log := std.log


Let's take a look at the files in the directory relative to the executing file (in this instance, this website's build script).

path := 'ls' `` path to executable
arguments := []
stdin := ''
stdoutFn := out => log(out)
exec(path, arguments, stdin, stdoutFn)

args gives us the command-line arguments for the current context. This can be useful if you're chaining Ink programs.

log('Arguments:')
each(args(), arg => log('  ' + arg))

$ ink execing-processes.ink
Arguments:
  ./ink-linux-1.9
  ../tmp/execing-processes.ink
{type: 'data', data: 'build.ink
highlight.ink
ink-darwin-1.9
ink-linux-1.9
test.ink
'}