sceall
Types
A reference to the spawned program.
pub opaque type ProgramHandle
Messages that will be sent to the BEAM process that called the
spawn_program function. These can be received using the select
function.
pub type ProgramMessage {
Data(program: ProgramHandle, data: BitArray)
Exited(program: ProgramHandle, status_code: Int)
}
Constructors
-
Data(program: ProgramHandle, data: BitArray)Data that the program printed to stdout or stderr.
Be aware, data printed could be too large or printed too slowly for one message! In these cases, the data will be delivered over multiple messages.
-
Exited(program: ProgramHandle, status_code: Int)The program exited.
pub type SendError {
SendWasAborted
CannotSendToExitedProgram
}
Constructors
-
SendWasAbortedThe port send operation was aborted
-
CannotSendToExitedProgramThe program has already exited
pub type SpawnProgramError {
NotEnoughBeamPorts
NotEnoughMemory
NotEnoughOsProcesses
ExternalCommandTooLong
NotEnoughFileDescriptors
OsFileTableFull
FileNotExecutable
FileDoesNotExist
}
Constructors
-
NotEnoughBeamPortsThere are not enough beam ports available.
-
NotEnoughMemoryThere is insufficient memory to spawn the executable.
-
NotEnoughOsProcessesThere are not enough OS processes available.
-
ExternalCommandTooLongThe external command is too long to execute.
-
NotEnoughFileDescriptorsThere are not enough file descriptors available.
-
OsFileTableFullThe OS file table is full.
-
FileNotExecutableThe file at the given path could not be executed.
-
FileDoesNotExistNo file exists at the given path.
Values
pub fn exit_program(program: ProgramHandle) -> Bool
Exit a program. Returns True if the program was stopped, returns False
if the program had already stopped.
The Exited message will not be sent if the program is stopped with this
function.kj
pub fn program_port(handle: ProgramHandle) -> port.Port
Get the BEAM port for a given program.
pub fn select(
selector: process.Selector(message),
program: ProgramHandle,
mapper: fn(ProgramMessage) -> message,
) -> process.Selector(message)
Add a message handler for messages from the spawned program. See
ProgramMessage for details.
Use this to handle program messages in your actor!
pub fn send(
program: ProgramHandle,
data: BitArray,
) -> Result(Nil, SendError)
Send some data to stdin of the program.
Sending is synchronous, with the sending process blocking until the operation completes.
pub fn spawn_program(
executable_path path: String,
working_directory directory: String,
command_line_arguments arguments: List(String),
environment_variables environment: List(#(String, String)),
) -> Result(ProgramHandle, SpawnProgramError)
Spawn an operating system, returning a reference to it that can be used to receive stdio data as messages.
There is no PATH variable resolution, so you cannot give the name of a
program. It must be a path to the executable.
The process that calls this function is the owner of the BEAM port for the spawned program. When this process exits the port and the program will be shut down.