[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Redirection and Pipelines

The input to a command, or the output from a command, can be redirected to files or, in some cases, other commands. Although there are subprograms in text_io package to perform some of these operations (e.g. set_output), the familliar Bourne shell syntax is also supported.

Redirecting Standard Input, Output and Error

  • > f - redirect standard output to file f, creating or overwriting f (not allowed in a restricted shell)
  • >> f - redirect standard output to file f, appending to f
  • < f - redirection input from file f
  • 2> f - redirect error output to file f, creating or overwriting f (not allowed in a restricted shell)
  • 2>> f - redirect error output to file f, appending to f
  • 2>&1 - redirect error output to standard output (must appear after a standard output redirection to redirect both to the same file)

The redirection operands should appear after the command.

=> ls > list_output.txt 2> list_errors.txt

These redirection operands also work with built-in shell commands like env or help. They will not work on subprograms like put_line.

The redirect operands are considered to be a command line convenience.  More powerful redirection is possible using the Text_IO package.

Bourne shell: SparForte doesn't use file descriptor numbers so redirecting arbitrary open files using the Bourne shell syntax is not possible. Use the text_io package instead.

Pipelines

Command pipelines are created by connecting one or more commands using the pipe (|) symbol.

=> ls | grep ".txt"

The result from a command pipeline is the result of the last command in the pipeline.  Pipelines can only have one input redirection (for the first command), one output redirection and one error redirection (for the final command).  Pipelines cannot be run in the background using &.
 

[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]