run_process_output.ncdi 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. include_guard "run_process_output"
  2. template run_process_output {
  3. alias(@_arg0) command;
  4. # We collect the results here.
  5. var(@false) succeeded;
  6. value("") output;
  7. Do {
  8. # Start child process.
  9. sys.start_process(command, "r", ["keep_stderr":"true"]) proc;
  10. If (proc.is_error) {
  11. _do->break();
  12. };
  13. # Get read pipe handle.
  14. proc->read_pipe() read_pipe;
  15. If (read_pipe.is_error) {
  16. _do->break();
  17. };
  18. # Read all contents.
  19. backtrack_point() read_again;
  20. read_pipe->read() read;
  21. If (read.not_eof) {
  22. output->append(read);
  23. read_again->go();
  24. };
  25. # Wait for the process to terminate.
  26. proc->wait() wait;
  27. val_different(wait.exit_status, "0") not_ok;
  28. If (not_ok) {
  29. _do->break();
  30. };
  31. # Assume success.
  32. succeeded->set(@true);
  33. };
  34. }