Skip to content
/ sceall Public

Spawn shell programs and stream their stdio using BEAM ports!

Notifications You must be signed in to change notification settings

lpil/sceall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sceall

Spawn shell programs and stream their stdio using BEAM ports!

Package Version Hex Docs

gleam add sceall@1
pub fn main() {
  // Spawn the `cat` program, which is typically available on Unix-like
  // operating systems.
  //
  // In this example we always use `let assert`, but in a real program
  // you would want to handle any errors.
  let assert Ok(program) =
    sceall.spawn_program(
      executable_path: "/bin/cat",
      working_directory: "./",
      command_line_arguments: [],
      environment_variables: [],
    )

  // We can send data to the running program. The `cat` program will
  // print any data it receives.
  let assert Ok(_) = sceall.send(program, <<"Hello, Joe!\n">>)
  let assert Ok(_) = sceall.send(program, <<"Hello, Mike!\n">>)

  // The stdout and stderr of the program is sent back using BEAM messages.
  //
  // A selector is used to receive these messages. If you are not familiar
  // with selectors check out the documentation for `gleam_erlang`.
  let selector =
    process.new_selector() |> sceall.select(program, function.identity)

  assert process.selector_receive(selector, 200)
    == Ok(sceall.Data(program, <<"Hello, Joe!\nHello, Mike!\n">>))

  // If the program exited itself we would get a `sceall.Exited` message,
  // which would contain the status code. `cat` doesn't exit by itself,
  // so we can use the `exit_program` function instead.
  sceall.exit_program(program)
}

Documentation can be found at https://hexdocs.pm/sceall.

Name

Sceall means shell in Gaeilge.

It has 1 syllable. sc as in the start of "skew", eall as in the end of "pal". Kinda like "skull" but with an "a" instead of a "u".

About

Spawn shell programs and stream their stdio using BEAM ports!

Resources

Stars

Watchers

Forks

Packages

No packages published