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

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl
      • lists.pl
      • broadcast.pl
      • shlib.pl -- Utility library for loading foreign objects (DLLs, shared objects)
      • option.pl -- Option list processing
      • thread_pool.pl
      • gensym.pl -- Generate unique symbols
      • settings.pl -- Setting management
      • arithmetic.pl
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl
      • pairs.pl
      • prolog_source.pl
      • record.pl
      • 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
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl
      • pprint.pl
      • atom.pl -- Operations on atoms
      • modules.pl -- Module utility predicates
      • occurs.pl
      • prolog_xref.pl
      • prolog_colour.pl -- Prolog syntax colouring support.
      • lazy_lists.pl -- Lazy list handling
      • ugraphs.pl
      • url.pl
      • www_browser.pl
      • prolog_pack.pl
      • git.pl -- Run GIT commands
      • rbtrees.pl
      • dif.pl -- The dif/2 constraint
      • charsio.pl -- I/O on Lists of Character Codes
      • prolog_stack.pl
      • edinburgh.pl
      • prolog_clause.pl
      • prolog_breakpoints.pl
      • wfs.pl
      • dialect.pl
      • prolog_code.pl
      • sort.pl
      • iostream.pl -- Utilities to deal with streams
      • dicts.pl
      • varnumbers.pl
      • backcomp.pl -- Backward compatibility
      • base32.pl
      • codesio.pl
      • coinduction.pl
      • date.pl -- Process dates and times
      • heaps.pl -- heaps/priority queues
      • statistics.pl
      • terms.pl -- Term manipulation
      • utf8.pl
      • when.pl
      • thread.pl -- High level thread primitives
      • prolog_coverage.pl
      • ansi_term.pl -- Print decorated text to ANSI consoles
      • prolog_config.pl
      • strings.pl
      • ctypes.pl -- Character code classification
      • writef.pl
      • hashtable.pl
      • listing.pl -- List programs and pretty print clauses
      • prolog_profile.pl -- Execution profiler
      • prolog_debug.pl
      • check.pl
      • optparse.pl
      • threadutil.pl -- Interactive thread utilities
      • persistency.pl
      • zip.pl
      • prolog_history.pl -- Per-directory persistent commandline history
      • prolog_versions.pl -- Demand specific (Prolog) versions
      • edit.pl
      • portray_text.pl
      • increval.pl
      • tables.pl
      • prolog_jiti.pl
      • nb_set.pl
      • explain.pl
      • make.pl
      • qsave.pl
      • prolog_codewalk.pl -- Prolog code walker
      • intercept.pl
      • help.pl
      • prolog_trace.pl
      • streams.pl -- Manage Prolog streams
        • with_output_to/3
      • fastrw.pl -- Fast reading and writing of terms
      • system.pl
      • shell.pl
      • quintus.pl
      • exceptions.pl
      • prolog_wrap.pl
      • prolog_metainference.pl -- Infer meta-predicate properties
      • rwlocks.pl
      • files.pl
      • macros.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, _)).