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 a fresh host (the host and every other piece of interpreter state are thread-local), so nothing leaks between calls and concurrent calls never share an output buffer. src is a PHP file’s text, so it starts in HTML mode: PHP code needs its <?php tag.

  • input is what STDIN, php://stdin and readline() read.
  • Output is captured below the output-buffering stack; fwrite(STDOUT, …) lands there too. Diagnostics are displayed into the output as the CLI displays them on stdout; their log copies still go to the process stderr.
  • The request shutdown runs as under the CLI: shutdown functions, destructors, then the open output buffers.
  • Err for a parse or compile error, an uncaught exception or fatal error (its message), a nonzero exit/die status (exit status N), or a panic in the runtime. exit(0), exit("text") and die with no status are Ok with the output up to that point.