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

  • swipl
    • library
      • error.pl
      • debug.pl -- Print debug messages and test assertions
      • apply.pl
      • lists.pl
      • broadcast.pl -- Event service
      • shlib.pl
      • option.pl
      • thread_pool.pl -- Resource bounded thread management
      • gensym.pl
      • settings.pl
      • arithmetic.pl
      • main.pl
      • 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
      • ordsets.pl
      • random.pl
      • base64.pl
      • aggregate.pl
      • yall.pl -- Lambda expressions
      • sandbox.pl -- Sandboxed Prolog code
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl
      • atom.pl
      • modules.pl
      • occurs.pl -- Finding and counting sub-terms
      • prolog_xref.pl -- Prolog cross-referencer data collection
      • prolog_colour.pl
      • lazy_lists.pl
      • ugraphs.pl
      • url.pl
      • www_browser.pl
      • prolog_pack.pl
      • git.pl
      • rbtrees.pl -- Red black trees
      • dif.pl -- The dif/2 constraint
      • charsio.pl
      • prolog_stack.pl
      • edinburgh.pl -- Some traditional Edinburgh predicates
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl -- Well Founded Semantics interface
      • dialect.pl
      • prolog_code.pl
      • sort.pl
      • iostream.pl -- Utilities to deal with streams
      • dicts.pl -- Dict utilities
      • varnumbers.pl -- Utilities for numbered terms
      • prolog_jiti.pl
      • intercept.pl -- Intercept and signal interface
      • increval.pl
      • tables.pl -- XSB interface to tables
      • help.pl
      • thread.pl
      • shell.pl
      • backcomp.pl -- Backward compatibility
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • prolog_versions.pl -- Demand specific (Prolog) versions
      • base32.pl
      • codesio.pl
      • coinduction.pl
      • date.pl
      • heaps.pl -- heaps/priority queues
      • statistics.pl -- Get information about resource usage
      • terms.pl
      • utf8.pl
      • when.pl
      • quintus.pl -- Quintus compatibility
      • check.pl
      • make.pl -- Reload modified source files
      • prolog_codewalk.pl -- Prolog code walker
      • listing.pl
      • edit.pl -- Editor interface
      • prolog_history.pl
      • prolog_profile.pl
      • threadutil.pl -- Interactive thread utilities
      • prolog_metainference.pl
      • ctypes.pl -- Character code classification
      • prolog_debug.pl
      • prolog_trace.pl -- Print access to predicates
      • portray_text.pl
      • prolog_coverage.pl -- Coverage analysis tool
      • prolog_autoload.pl
      • persistency.pl
      • zip.pl
      • macros.pl
      • explain.pl
      • optparse.pl
      • qsave.pl
      • system.pl -- System utilities
      • streams.pl -- Manage Prolog streams
        • with_output_to/3
      • rwlocks.pl
      • writef.pl
      • nb_set.pl
      • fastrw.pl -- Fast reading and writing of terms
      • prolog_wrap.pl -- Wrapping predicates
      • strings.pl
      • hashtable.pl
      • oset.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, _)).