A The SWI-Prolog library
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(aggregate): Aggregation operators on backtrackable predicates
        • library(ansi_term): Print decorated text to ANSI consoles
        • library(apply): Apply predicates on a list
        • library(assoc): Association lists
        • library(broadcast): Broadcast and receive event notifications
        • library(charsio): I/O on Lists of Character Codes
        • library(check): Consistency checking
        • library(clpb): CLP(B): Constraint Logic Programming over Boolean Variables
        • library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains
        • library(clpqr): Constraint Logic Programming over Rationals and Reals
        • library(csv): Process CSV (Comma-Separated Values) data
        • library(dcg/basics): Various general DCG utilities
        • library(dcg/high_order): High order grammar operations
        • library(debug): Print debug messages and test assertions
        • library(dicts): Dict utilities
        • library(error): Error generating support
        • library(exceptions): Exception classification
        • library(fastrw): Fast reading and writing of terms
        • library(gensym): Generate unique symbols
        • library(heaps): heaps/priority queues
        • library(increval): Incremental dynamic predicate modification
        • library(intercept): Intercept and signal interface
        • library(iostream): Utilities to deal with streams
        • library(listing): List programs and pretty print clauses
        • library(lists): List Manipulation
        • library(macros): Macro expansion
        • library(main): Provide entry point for scripts
        • library(nb_set): Non-backtrackable set
        • library(writef): Old-style formatted write
        • library(www_browser): Open a URL in the users browser
        • library(occurs): Finding and counting sub-terms
        • library(option): Option list processing
        • library(optparse): command line parsing
        • library(ordsets): Ordered set manipulation
        • library(pairs): Operations on key-value lists
        • library(persistency): Provide persistent dynamic predicates
        • library(pio): Pure I/O
        • library(portray_text): Portray text
        • library(predicate_options): Declare option-processing of predicates
        • library(prolog_coverage): Coverage analysis tool
        • library(prolog_debug): User level debugging tools
        • library(prolog_jiti): Just In Time Indexing (JITI) utilities
        • library(prolog_trace): Print access to predicates
        • library(prolog_versions): Demand specific (Prolog) versions
        • library(prolog_xref): Prolog cross-referencer data collection
        • library(quasi_quotations): Define Quasi Quotation syntax
        • library(random): Random numbers
        • library(rbtrees): Red black trees
        • library(readutil): Read utilities
        • library(record): Access named fields in a term
        • library(registry): Manipulating the Windows registry
        • library(rwlocks): Read/write locks
        • library(settings): Setting management
        • library(shell): Elementary shell commands
          • shell/0
          • shell_command/1
          • cd/0
          • cd/1
          • pushd/0
          • pushd/1
          • popd/0
          • dirs/0
          • pwd/0
          • ls/0
          • ls/1
          • mv/2
          • rm/1
          • file_style/2
          • cls/0
        • library(statistics): Get information about resource usage
        • library(strings): String utilities
        • library(simplex): Solve linear programming problems
        • library(solution_sequences): Modify solution sequences
        • library(tables): XSB interface to tables
        • library(tableutil): Table inspection and statistics utilities
        • library(terms): Term manipulation
        • library(thread): High level thread primitives
        • library(thread_pool): Resource bounded thread management
        • library(ugraphs): Graph manipulation library
        • library(url): Analysing and constructing URL
        • library(varnumbers): Utilities for numbered terms
        • library(yall): Lambda expressions
    • Packages

A.54 library(shell): Elementary shell commands

This library provides some basic (POSIX) shell commands defined in Prolog, such as pwd and ls for situations where there is no shell available or the shell output cannot be captured. Note that in recent versions (since 10.1.13) the GUI frontend swipl-win can capture process output on all supported platforms.

shell
Execute an interactive shell. Uses shell_command/1 to find a suitable shell.

The shell's exit status is not our business, so shell/0 succeeds whatever it is. Note that if the shell cannot be executed shell/2 raises an exception.

shell_command(-Shell:atom)
True when Shell is the preferred executable for running an interactive shell. Used by shell/0. The following options are tried to find a suitable shell command:

  1. The Prolog flag shell
  2. The environment variable %comspec% (Windows only)
  3. The environment variable $SHELL
  4. The Prolog flag posix_shell
Errors
existence_error(config, shell) if no suitable shell can be found.
cd
cd(Dir)
Change working directory
pushd
pushd(+Dir)
popd
dirs
Manage the directory stack:

  • pushd/1 is as cd/1, pushing th old directory on a stack
  • pushd/0 swaps the current directory with the top of the stack
  • popd/0 pops to the top of the stack
  • dirs/0 lists the current directory and the stack.
pwd
Print current working directory
ls
ls(+Pattern)
Listing similar to Unix ls -F, flagging directories with /. If the terminal supports it, Prolog source files are rendered as links using the OSC 8 escape sequence. When using Epilog, clicking a Prolog file opens it in the editor.
[det]mv(+From, +To)
Move (Rename) a file. If To is a directory, From is moved into the directory. Uses expand_file_name/2 on the From argument.
[det]rm(+File)
Remove (unlink) a file
[det,multifile]file_style(++File, =Style)
True when File should be listed as a terminal hyperlink. The default only links Prolog source files.
Style is either url to make a hyperlink or a valid style argument for ansi_format/3.
cls
CLear Screen. Emits ANSI control characters to clear the terminal.