Skip to main content

run_program

Function run_program 

Source
pub fn run_program(src: &str, input: &str) -> Result<String, String>
Expand description

Run src as a complete program with input as its stdin and return everything it wrote to stdout.

Each call runs on its own thread with crate::JS_STACK_SIZE of stack and a freshly reset host, so nothing leaks between calls and concurrent calls never share a buffer. Stdout writes (console.log, process.stdout.write) are captured through crate::host::JsHost::begin_stdout_capture; stderr still reaches the process. process.stdin, fs.readFileSync(0) and readline read input.

A compile error, an uncaught exception, a nonzero process.exitCode or process.exit(n) with n != 0, and a panic inside the runtime return Err. process.exit(0) returns Ok with the output written so far.