HPlogo Command Interpreter Access and Variables Programmer's Guide: Series HP 3000 Computer Systems > Chapter 8 Command Input/Output Redirection (CIOR)

Redirecting Command Input and Output

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Redirection is accomplished with the use of the following simple redirection indicators <, > or >>, followed by a file name, or backreference to a file equation.

The < sign indicates that CI input comes from the specified file. The > sign indicates that CI output goes to the specified file. The >> sign also indicates that CI output goes to the specified file; however, output is appended to the file (if it exists) so existing data is not overwritten.

Redirection is supported for single files only; therefore, wildcarding on the file name is meaningless and returns an error.

The following are examples of CIOR.

Redirecting Command Input

To redirect command input you would enter:

   command < infile

Command can be any MPE/iX command except for the following:

  • CALC

  • COMMENT

  • ELSEIF

  • IF

  • REMOTE

  • SETVAR

  • SETJCW

  • TELL

  • TELLOP

  • WARN

  • WHILE

and infile is the file that contains the input to that command.

For example:

   editor < edinput 

This invokes the EDITOR and instructs it to read data from the file edinput. The data is used by EDITOR as if it was being typed as input at the terminal.

Redirecting Command Output

To redirect command output you would enter:

   command > outfile

Once again, command is as described above and outfile is the file which contains the output of the command.

For example:

   showme > userfile

This invokes the showme command and instructs it to write its output to a file called userfile.

Redirecting Both Command Input and Output

CIOR enables you to redirect both input and output at the same time.

To accomplish this, you would enter:

   command <infile >outfile

For example,

   editor <edinput >$null

This invokes EDITOR, instructs it to read input from file edinput and to write output to $NULL. Output from EDITOR for includes the banner, the prompt and all other EDITOR output.

Redirecting I/O with a File Backreference

Backreferencing a file equation with CIOR is both simple and useful. To accomplish it you enter:

   file formaldesig1;parm...;parm...

   file formaldesig2;parm...;parm...

   command <*formaldesig1 >*formaldesig2
NOTE: The FILE command accepts the MPE escape syntax, allowing you to reference HFS (hierarchical file system) file names, but only on the right hand side of the equation. Refer to MPE/iX Commands Reference Manual (32650-90003) for more information about using the FILE command with HFS names.

You may backreference both input and output to different file equations or either input or output to a single file equation.

For example:

   file sourclst;save;rec=-80,,f,ascii

   listfile S@, qualify > *sourclst

This example first establishes file equations to override redirection file defaults. It then issues a listfile command and directs its output to the file sourclst. The ;save option in the file equation keeps the file in the permanent domain. Without ;save the file sourclst would stay in the default (temporary) file domain.

Redirection file defaults are discussed in a later section in this chapter.

NOTE: The LISTFILE command accepts the MPE escape syntax, allowing you to reference HFS (hierarchical file system) file names, but only on the right hand side of the equation. Refer to MPE/iX Commands Reference Manual (32650-90003) for more information about using the LISTFILE command with HFS names.

Appending Redirected Command Output

When the > sign is used, command output is redirected to the specified file and it begins writing output at the beginning of the file. When the >> sign is used, command output is redirected to the specified file, but it is appended to the file, so information already contained in the file is not overwritten. If >> is used and the file does not exist, it will be created.

The append form of output redirection (>> sign) is useful when the output is a logging message or has a logging function, or when the user is creating a file with several commands. If your goal is to create a file containing only the output of the current command you should use the > sign and not the >> sign.

Redirection supports HFS (hierarchical file system) names. ECHO Hi There! >> ./somefile appends to the file ./somefile

To append redirected output enter:

   command >>outfile

For example:

   echo text file1 > edinput

   echo find "patt1" >> edinput

   echo delete >> edinput

   echo keep >> edinput

   echo exit >> edinput

   

The first line in this example produces the temporary file edinput. The next four lines append edit commands to this file. The result is a file of commands that might be read by the EDITOR subsystem with CIOR in the following command:

   editor <edinput >$null

This command invokes the EDITOR and causes it to read the commands previously written to the file edinput. Command output, in this case, is redirected to $NULL.

Printing the edinput file shows the commands that the EDITOR would read as input:

   print edinput

   text file1

   find "patt1"

   delete

   keep

   exit

Redirecting Output to a Device File

To redirect output to a device file (such as a printer), simply backreference a file equation for the device as follows:

   file formaldesig;dev=...

   command >*formaldesig

For example:

   file lp602;dev=epoc;env=lp602.hpenv.sys

   listfile @.@.myaccount,-2 > *lp602

This example would send a listing of all access control definition (ACD) data to the printer defined by the file equation with formal file designator lp602.

The Append Option with Device Files

The redirection append option (use of the >> sign) produces a different result with device files than with disk files. For example, you could enter:

   file lp602;dev=epoc;env=lp602.hpenv.sys

   listfile @.@.myaccount,-2 > *lp602

   listfile @.@.myaccount,4 >> *lp602

Both listfile commands are directed to a printer in this example. When the first listfile command finishes, its spoolfile is closed and made ready for printing. Once this happens to a spoolfile it cannot be reopened. For this reason, the second listfile command cannot append to the first file even though the >> sign has been used. The second listfile command simply writes another spoolfile.

Feedback to webmaster