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

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl
      • lists.pl -- List Manipulation
      • broadcast.pl
      • shlib.pl -- Utility library for loading foreign objects (DLLs, shared objects)
      • option.pl -- Option list processing
      • thread_pool.pl
      • gensym.pl
      • settings.pl -- Setting management
      • arithmetic.pl
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl -- Manage operators
      • pairs.pl
      • prolog_source.pl -- Examine Prolog source-files
      • record.pl -- Access compound arguments by name
      • quasi_quotations.pl
      • pure_input.pl -- Pure Input from files and streams
      • solution_sequences.pl
      • ordsets.pl -- Ordered set manipulation
      • random.pl -- Random numbers
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl -- Aggregation operators on backtrackable predicates
      • yall.pl
      • sandbox.pl
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl -- Binary associations
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl
      • atom.pl
      • modules.pl -- Module utility predicates
      • occurs.pl
      • prolog_xref.pl
      • prolog_colour.pl
      • lazy_lists.pl
      • ugraphs.pl
      • url.pl
      • www_browser.pl
      • prolog_pack.pl -- A package manager for Prolog
      • git.pl
      • rbtrees.pl -- Red black trees
      • dif.pl -- The dif/2 constraint
      • charsio.pl
      • prolog_stack.pl -- Examine the Prolog stack
      • edinburgh.pl
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl
      • dialect.pl -- Support multiple Prolog dialects
      • prolog_code.pl -- Utilities for reasoning about code
      • sort.pl
      • iostream.pl -- Utilities to deal with streams
      • dicts.pl -- Dict utilities
      • varnumbers.pl
      • base32.pl
      • codesio.pl
      • coinduction.pl -- Co-Logic Programming
      • date.pl -- Process dates and times
      • heaps.pl
      • statistics.pl -- Get information about resource usage
      • terms.pl -- Term manipulation
      • utf8.pl
      • when.pl -- Conditional coroutining
      • backcomp.pl
      • prolog_history.pl
      • prolog_wrap.pl
      • prolog_codewalk.pl
      • prolog_metainference.pl
      • thread.pl
      • ansi_term.pl
      • increval.pl
      • tables.pl -- XSB interface to tables
      • listing.pl -- List programs and pretty print clauses
      • quintus.pl
      • shell.pl -- Elementary shell commands
      • threadutil.pl -- Interactive thread utilities
      • prolog_debug.pl
      • oset.pl
      • optparse.pl
      • make.pl -- Reload modified source files
      • strings.pl
      • check.pl -- Consistency checking
      • prolog_coverage.pl
      • prolog_jiti.pl -- Just In Time Indexing (JITI) utilities
      • writef.pl
      • prolog_versions.pl
      • zip.pl
      • help.pl -- Text based manual
      • prolog_trace.pl
      • intercept.pl
      • portray_text.pl
      • hashtable.pl -- Hash tables
      • persistency.pl -- Provide persistent dynamic predicates
      • ctypes.pl -- Character code classification
      • system.pl -- System utilities
      • fastrw.pl
      • nb_set.pl -- Non-backtrackable sets
      • prolog_profile.pl -- Execution profiler
      • macros.pl
      • edit.pl
      • qsave.pl
      • explain.pl
      • streams.pl -- Manage Prolog streams
        • with_output_to/3
      • exceptions.pl
      • files.pl
      • prolog_config.pl
      • rwlocks.pl
      • prolog_autoload.pl -- Autoload all dependencies
 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, _)).