[Digital logo]
[HR]

OpenVMS User's Manual


Previous | Contents

The command sequences in a subshell are executed in a subprocess environment. DCL waits for the subshell to complete before executing the next command sequence. The ( ) separator is similar to the SPAWN/WAIT command.

16.29.5 Using the PIPE Command for Background Execution

Command sequences can be executed in a subprocess environment by using the following form:

PIPE  command-sequence [ separator command-sequence]...  & 

DCL does not wait for the command sequences to finish. Control passes back to DCL once the background subprocess is created.

16.29.6 Using the PIPE Command for Input/Output Redirection

A command sequence can redirect its SYS$INPUT, SYS$OUTPUT, or SYS$ERROR to a file during execution of the command as follows:

A pipeline-segment command can also redirect its SYS$INPUT, SYS$OUTPUT or SYS$ERROR. However, SYS$OUTPUT redirection is allowed only for the last pipeline-segment command, and SYS$INPUT redirection is allowed only for the first pipeline-segment command.

Note that a PIPE command redirection is different from that created using the DEFINE or ASSIGN command. The differences are as follows:

When SYS$OUTPUT is redirected, the redirected output file is always created, whether or not the command sequence actually writes to SYS$OUTPUT. If a version of a file with the same name as the redirected output file already exists, a new version of that file is created. (This behavior is the same as using the DEFINE or ASSIGN command to redefine SYS$OUTPUT in supervisor mode.) Note that the redirected file is created before the command sequence is executed. If the redirected file is also used in the command sequence, the operation may fail, as in the following example:

$ PIPE SEARCH TRANS.LOG "alpha" > TRANS.LOG
%SEARCH-W-OPENIN, error opening TRANS.LOG;2 as input
-RMS-E-FLK, file currently locked by another user
In this example, a new version of TRANS.LOG is created and opened for write access; the SEARCH command then tries to get read access to the most recent version of TRANS.LOG instead of the expected previous version.

When SYS$ERROR is redirected, the redirected error file is only created when the command sequence actually writes to the SYS$ERROR during execution, and there is no existing file with the same name as the redirected error file. If a file with the same name as the redirected error file already exists, that file is opened as the redirected error file. The error output generated by this command sequence is then appended to the end of the redirected error file. (This behavior is the same as using the DEFINE or ASSIGN command to redefine SYS$ERROR in supervisor mode.)

16.29.7 Interrupting a PIPE Command

You can interrupt a PIPE command by pressing Ctrl/Y. If the PIPE command is executing in a pipeline or a subshell command sequence, the command sequence and the PIPE command are deleted. In this case, a CONTINUE command entered immediately after the interrupt will not resume the execution of the PIPE command.

If the PIPE command is executing a command sequence other than a subshell or a pipeline command sequence, DCL behaves as if the command sequence were entered as a DCL command without the PIPE command verb and interrupted by Ctrl/Y. See Section 3.12.2 and Section 15.25 for more information on the Ctrl/Y interrupt.

16.29.8 Improving Subprocess Performance

A PIPE command can generate a number of subprocesses during execution. Often, the applications invoked by command sequences do not depend on the process logical names and symbol names. In this case, the spawning of subprocesses can be accelerated by using the /NOLOGICAL_NAMES and /NOSYMBOLS qualifiers, which suppress the passing of process logical names and symbols to the subprocesses created by the PIPE command.

16.29.9 Examples

Following are examples of using the PIPE command.


Chapter 17
Lexical Functions: Obtaining and Manipulating Information

17.1 Overview

Lexical functions are command language constructs that the DCL interpreter evaluates and substitutes before it interprets a command string. This chapter includes information on:

For additional information on lexical functions, refer to online Help. For additional information on the commands discussed in this chapter, refer to the OpenVMS DCL Dictionary.

17.2 About Lexical Functions

Lexical functions can be used to obtain information about:

Many lexical functions return information that you can also get from DCL commands.

17.2.1 Information Manipulation

You can manipulate information in a command procedure more easily if you obtain it from a lexical function rather than from a command. For example, you can use either the F$ENVIRONMENT function or the SHOW DEFAULT command to obtain the name of your current default directory. The differences are as follows:

17.3 Obtaining Information About Your Process

The following sections describe how to obtain information about your process.

17.3.1 Process Lexical Functions

You often change process characteristics for the duration of a command procedure and then restore them. You can use the following lexical functions to obtain information about your process:
F$DIRECTORY Returns the current default directory string.
F$ENVIRONMENT Returns information about the command environment for your process.
F$GETJPI Returns accounting, status, and identification information about your process or about other processes on the system.
F$MODE Shows the mode in which your process is executing.
F$PRIVILEGE Indicates whether your process has the specified privileges.
F$PROCESS Returns the name of your process.
F$SETPRV Sets the specified privileges. This function also indicates whether the specified privileges were previously enabled before you used the F$SETPRV function.
F$USER Returns your user identification code (UIC).
F$VERIFY Indicates whether verification is on or off.

17.3.2 Commonly Changed Process Characteristics

The following table shows process characteristics that are commonly changed in command procedures; it also gives the lexical functions that save these characteristics and the DCL commands that restore the original settings.
Characteristic Operation Command or Lexical Function
Control characters Save F$ENVIRONMENT("CONTROL")
Restore SET CONTROL
DCL prompt Save F$ENVIRONMENT("PROMPT")
Restore SET PROMPT
Default protection Save F$ENVIRONMENT("PROTECTION")
Restore SET PROTECTION/DEFAULT
Key state Save F$ENVIRONMENT("KEY_STATE")
Restore SET KEY
Message format Save F$ENVIRONMENT("MESSAGE")
Restore SET MESSAGE
Privileges Save F$PRIVILEGE or F$SETPRV
Restore F$SETPRV or SET PROCESS/PRIVILEGES
Verification Save F$VERIFY or F$ENVIRONMENT
Restore F$VERIFY or SET VERIFY

17.3.3 Saving Process Characteristics

If you save process characteristics, you must ensure that an error or Ctrl/Y interruption does not cause the procedure to exit before you restore the original characteristics. (See Chapter 15 for more information on handling errors and Ctrl/Y interruptions.)

17.3.4 Changing Verification Settings

You can use the F$VERIFY lexical function to disable verification for the duration of a command procedure. This prevents users from displaying a procedure's contents while executing the procedure.

There are two types of verification:

By default, the SET [NO]VERIFY command and the F$VERIFY function turn both types of verification on or off. In general, the procedure and image verification settings in a procedure are the same (both on or both off). However, if you decide to change the settings, save each verification setting separately.

17.3.5 Examples

17.3.6 Time Stamping

If you are using time-stamping, remember that it applies only if verification is enabled. For more information on time-stamping and the SET PREFIX command, see the OpenVMS DCL Dictionary or refer to DCL help.

17.3.7 Changing Default File Protection

You may want to change the default file protection within a command procedure. The following command procedure changes the default protection associated with files created while the procedure is executing. The procedure restores the original default file protection before terminating.

$ SAVE_PROT = F$ENVIRONMENT("PROTECTION") 
$ SET PROTECTION = (SYSTEM:RWED, OWNER:RWED, GROUP, WORLD)/DEFAULT 
   .
   .
   .
$ SET PROTECTION=('SAVE_PROT')/DEFAULT 
$ EXIT 

Note that the F$ENVIRONMENT function returns the default protection code using the syntax required by the SET PROTECTION command. This lets you use the symbol SAVE_PROT with the SET PROTECTION command to restore the original default file protection.

17.4 Obtaining Information About the System

The following sections describe how to obtain information about the system.

17.4.1 System Information

You can use the following lexical functions to obtain information about the system:
F$CONTEXT Specifies selection criteria to use with the F$PID function. The F$CONTEXT function enables the F$PID function to obtain information about processes from any node in a VMScluster.
F$CSID Returns a VMScluster identification number and updates the context symbol to point to the current position in the system's VMScluster node list.
F$GETQUI Returns information about queues, batch and print jobs currently in those queues, form definitions, and characteristic definitions kept in the system job queue file.
F$GETSYI Returns information about your local system or about a node in your VMScluster (if your system is part of a VMScluster).
F$IDENTIFIER Converts identifiers from named to numeric format or from numeric to named format.
F$MESSAGE Returns the message text associated with a status code.
F$PID Returns the process identification (PID) number for processes that you are allowed to examine.
F$TIME Returns the current date and time.

17.4.2 Determining Your VMScluster Node Name

If your system is part of a VMScluster environment where you can log in to many different nodes, you can set the DCL prompt to indicate which node you are currently using. To do this, include the F$GETSYI function in your login command procedure to determine the node name. Then use the SET PROMPT command to set a unique prompt for the node.

If you want to use only a portion of the node name in your prompt string, use the F$EXTRACT function to extract the appropriate characters. See Section 17.7.3 for more information on extracting characters.

17.4.3 Example

In the following example, the symbol NODE is defined as FF$GETSYI("NODENAME") and then the node name is used as the prompt:

$ NODE = F$GETSYI("NODENAME") 
$ SET PROMPT = "''NODE'$ " 
   .
   .
   .

17.4.4 Obtaining Queue Information

You can use the F$GETQUI function to get many types of information about batch and print queues. You must have read access to the job, SYSPRV privilege, or OPER privilege to obtain information about jobs and files in queues.

17.4.5 Example

The following example shows how to determine if the batch queue VAX1_BATCH is in a stopped state. The value returned is either true or false. If the queue is not stopped, the command procedure submits a job to the queue:

$ QSTOPPED = F$GETQUI("DISPLAY_QUEUE", "QUEUE_STOPPED", "VAX1_BATCH") 
$ IF QSTOPPED THEN GOTO NOBATCH 
$ SUBMIT/QUEUE=VAX1_BATCH TEST.COM 
$ NOBATCH: 
   .
   .
   .
 

17.4.6 Obtaining Process Information

You can use the F$PID function to get the process identification (PID) number for all processes that you are allowed to examine. You can obtain PID numbers:

After you obtain a PID number, you can use the F$GETJPI function to obtain specific information about the process.

17.4.7 Examples

17.4.8 F$CONTEXT Lexical Function

To obtain information about processes from any node in a VMScluster, use the F$CONTEXT function.

17.4.9 Example

In the following example, F$CONTEXT is called three times to set up selection criteria:

$!Establish an error and Ctrl/Y handler 
$! 
$ ON ERROR THEN GOTO error 
$ ON CONTROL_Y THEN GOTO error 
$! 
$ ctx = "" 
$ temp = F$CONTEXT ("PROCESS", ctx, "NODENAME", "*","EQL") (1)
$ temp = F$CONTEXT ("PROCESS", ctx, "USERNAME", "M*,SYSTEM","EQL") (2)
$ temp = F$CONTEXT ("PROCESS", ctx, "CURPRIV", "SYSPRV,OPER", "ALL") (3)
$! 
$!Loop over all processes that meet the selection criteria. 
$!Print the PID number and the name of the image for each process. 
$! 
$loop: (4)
$ pid = F$PID(ctx) 
$ IF pid .EQS. "" 
$ THEN 
$     GOTO endloop                     
$ ELSE 
$     image = F$GETJPI(pid,"IMAGNAME") (5)
$     SHOW SYMBOL pid   
$     WRITE SYS$OUTPUT image (6)
$     GOTO loop 
$ ENDIF 
$!The loop over the processes has ended. 
$! 
$endloop: 
$! 
$ EXIT 
$! 
$!Error handler. Clean up the context's memory with 
$!the CANCEL selection item keyword. 
$! 
$error: 
$ IF F$TYPE(ctx) .eqs. "PROCESS_CONTEXT" THEN - (7)
-$ temp = F$CONTEXT ("PROCESS", ctx, "CANCEL") (8)
$! 
$ EXIT 

As you examine the example, note the following:

  1. The first call requests that the search take place on all nodes in the VMScluster.
  2. The second call requests that only the processes whose user name either starts with an M or is SYSTEM be processed.
  3. The third call restricts the selection to those processes whose current privileges include both SYSPRV (system privilege) and OPER (operator) and can have other privileges set.
  4. The command lines between the labels "loop" and "endloop" continually call F$PID to obtain the processes that meet the criteria set up in the F$CONTEXT calls.
  5. After retrieving each PID number, F$GETJPI is called to return the name of the image running in the process.
  6. Finally, the procedure displays the name of the image.
  7. In case of error or a Ctrl/Y operation, control is passed to error and the context is closed if necessary.
  8. Note the check for the symbol type PROCESS_CONTEXT. If the symbol has this type, selection criteria must be canceled by a call to F$CONTEXT. If the symbol is not of the type PROCESS_CONTEXT, either selection criteria have not been set up yet in F$CONTEXT or the symbol was used with F$PID until an error occurred or until the end of the process list was reached.

17.5 Obtaining Information About Files and Devices

You can use the following lexical functions to obtain information about files and devices:
F$DEVICE Returns the device names of all devices on a system that meet the specified selection criteria
F$FILE_ATTRIBUTES Returns information about file attributes
F$GETDVI Returns information about a specified device
F$PARSE Parses a file specification and returns the requested field or fields
F$SEARCH Searches a directory for a file

17.5.1 Searching for Devices

To get information on a particular device by using the system service $GETDVI, you must provide the device name to the service. If you do not know the device name, you can find it by using the lexical function F$DEVICE.


Previous | Next | Contents | [Home] | [Comments] | [Ordering info] | [Help]

[HR]

  6489P033.HTM
  OSSG Documentation
  22-NOV-1996 13:17:26.41

Copyright © Digital Equipment Corporation 1996. All Rights Reserved.

Legal