/usr/local/lib/swipl/library/streams.pl
All Application Manual Name SummaryHelp

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl -- Apply predicates on a list
      • lists.pl
      • broadcast.pl
      • shlib.pl
      • option.pl -- Option list processing
      • thread_pool.pl -- Resource bounded thread management
      • gensym.pl -- Generate unique symbols
      • settings.pl
      • arithmetic.pl
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl
      • pairs.pl -- Operations on key-value lists
      • prolog_source.pl -- Examine Prolog source-files
      • record.pl -- Access compound arguments by name
      • quasi_quotations.pl -- Define Quasi Quotation syntax
      • pure_input.pl
      • solution_sequences.pl -- Modify solution sequences
      • ordsets.pl -- Ordered set manipulation
      • random.pl -- Random numbers
      • base64.pl
      • aggregate.pl
      • yall.pl
      • sandbox.pl -- Sandboxed Prolog code
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl -- Analyse format specifications
      • predicate_options.pl
      • csv.pl
      • pprint.pl
      • atom.pl
      • modules.pl -- Module utility predicates
      • occurs.pl -- Finding and counting sub-terms
      • prolog_xref.pl
      • prolog_colour.pl
      • lazy_lists.pl
      • ugraphs.pl -- Graph manipulation library
      • url.pl -- Analysing and constructing URL
      • www_browser.pl
      • prolog_pack.pl
      • git.pl
      • utf8.pl
      • dialect.pl -- Support multiple Prolog dialects
      • system.pl -- System utilities
      • terms.pl -- Term manipulation
      • date.pl -- Process dates and times
      • persistency.pl -- Provide persistent dynamic predicates
      • iostream.pl -- Utilities to deal with streams
      • prolog_stack.pl
      • edinburgh.pl
      • prolog_clause.pl
      • prolog_breakpoints.pl -- Manage Prolog break-points
      • wfs.pl -- Well Founded Semantics interface
      • prolog_code.pl
      • sort.pl
      • dicts.pl
      • dif.pl
      • varnumbers.pl
      • pio.pl -- Pure I/O
      • base32.pl
      • charsio.pl -- I/O on Lists of Character Codes
      • codesio.pl
      • coinduction.pl
      • heaps.pl -- heaps/priority queues
      • rbtrees.pl
      • statistics.pl -- Get information about resource usage
      • when.pl
      • backcomp.pl
      • prolog_versions.pl -- Demand specific (Prolog) versions
      • portray_text.pl
      • explain.pl
      • threadutil.pl -- Interactive thread utilities
      • prolog_debug.pl
      • thread.pl -- High level thread primitives
      • prolog_profile.pl -- Execution profiler
      • check.pl -- Consistency checking
      • intercept.pl
      • increval.pl
      • tables.pl
      • hashtable.pl
      • quintus.pl
      • prolog_trace.pl
      • prolog_wrap.pl
      • strings.pl
      • edit.pl -- Editor interface
      • help.pl -- Text based manual
      • macros.pl -- Macro expansion
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • optparse.pl -- command line parsing
      • ctypes.pl -- Character code classification
      • shell.pl
      • prolog_metainference.pl
      • prolog_history.pl
      • prolog_config.pl
      • prolog_coverage.pl
      • listing.pl -- List programs and pretty print clauses
      • qsave.pl
      • zip.pl
      • prolog_autoload.pl -- Autoload all dependencies
      • make.pl
      • exceptions.pl
      • prolog_codewalk.pl -- Prolog code walker
      • nb_set.pl
      • writef.pl
      • tty.pl
      • prolog_jiti.pl
      • streams.pl -- Manage Prolog streams
        • with_output_to/3
      • rwlocks.pl
 with_output_to(?Output, :Goal, +Options) is det
Run Goal and once/1 while capturing all output to all streams (current_output, user_output and user_error) in the string Output. Options processed:
capture(ListOfStreams)
List of streams to capture. Default is [], causing the predicate to call with_output_to/2. The only admissible list elements are the alias names for the Prolog standard streams. As current_output is always captured, the only two values are user_output and user_error
color(Boolean)
When true, pretend the output is a terminal, causing messages to use ANSI term escape sequences for color.

For example, the following captures an error message. Note that we must catch and print the message inside Goal. If we do not do so the exception of Goal is simply propagated into the environment without binding Output.

?- with_output_to(string(Out),
                  catch(A is log(-1), E, print_message(error, E)),
                  [capture([user_error]), color(true)]).
Out = "\u001B[1;31mERROR: is/2: Arithmetic: \c
       evaluation error: `undefined'\n\u001B[0m",
E = error(evaluation_error(undefined), context(system:(is)/2, _)).