Getting Input Data into Command Procedures

Some programs you may wish to execute from within command procedures may require input from the terminal keyboard while they run. Alternatively, your command procedure may wish to solicit keyboard input for its own purposes, not to be passed to a program. These are separate issues with separate solutions.

First, input to programs will be discussed, then input to the procedure itself.

Passing Embedded Data into Programs

Some programs require keyboard input while running. So long as a program accepts data in the form of complete lines, DCL allows you to pass data to such programs. Programs that accept one keystroke at a time may or may not work properly from within a procedure.

To pass lines of text to a program, simply insert the data lines into the command procedure following the command that executes the program. Do not precede these lines with a dollar sign. When DCL encounters the next command (a line preceded by a dollar sign), it notifies the program that there is no more data by signaling an end-of-file (EOF) condition.

The following is an example using the OpenVMS MAIL facility with data embedded in a command procedure:

     $ !     $ ! Send mail to MIKE     $ !     $ mail     send/subject="Message from a procedure" (In response to "MAIL>" prompt)     mike  (In response to "To:" prompt)     This message was sent from within a command procedure. (Line in message)      $ ! (Next line starting with a dollar sign terminates input)     $ exit 

Passing Keyboard Data into Programs

Sometimes, you may want a command procedure to run a program that requires input directly from the terminal keyboard.

Most programs accept input from SYS$INPUT, a logical name that usually identifies your terminal. However, when running a command procedure, SYS$INPUT identifies the disk device containing the procedure. How, then, do we cause a program running from within a procedure to accept input from the keyboard?

When executing a procedure, the logical name SYS$COMMAND still identifies the terminal. In your procedure, you may temporarily assign the value of SYS$COMMAND to SYS$INPUT. This allows a program running from within a procedure to receive keyboard input:

     $ !     $ ! This example allows keyboard input to a program running under a command     $ ! procedure.  We temporarily override the normal input stream by the     $ ! following DEFINE command, causing input to come temporarily from the     $ ! terminal keyboard.     $ !     $ define/user_mode sys$input sys$command ! make the keyboard SYS$INPUT     $ edit/edt somefile.txt ! The EDT program will receive from the keyboard     $ !     $ ! (The /USER_MODE qualifier above automatically cancels the definition     $ ! at the end of the EDT session.)     $ !     $ exit 

Reading Keyboard Input into Procedures

Sometimes your command procedures may wish to read keyboard data for their own use, not to be passed to a program. You may use either of two methods for this: READ or INQUIRE. READ may be used to read data from a file or from the keyboard (when you specify SYS$COMMAND as the source). INQUIRE reads from SYS$COMMAND only. Each of them assigns the keyboard input to a symbol. Both are shown in the following example:

     $ !     $ ! Show two different methods for reading keyboard data.  Both of these     $ ! methods assign the string to a local symbol.     $ !     $ ! First, INQUIRE.  INQUIRE converts your input to upper case (unless in     $ ! quotes) and compresses multiple spaces.  It supplies a colon at the end of     $ ! the prompt unless you use /NOPUNCTUATION.  If you omit the prompt,     $ ! the symbol name will be used by default; in this case, "NAME:."     $ !     $ write sys$output "The INQUIRE command:"     $ INQUIRE name "Please enter your name "     $ show symbol name     $ !     $ ! Now a READ from SYS$COMMAND is shown. This does not convert your input     $ ! to upper case or compress it. It preserves quotes, if present, in the     $ ! input data.     $ !     $ write sys$output "The READ command:"     $ READ sys$command name /prompt="Please enter your name : "     $ show symbol name     $ !     $ exit 

When executed, this procedure produces the following:

     $ @KEYBOARD_EXAMPLE     The INQUIRE command:     Please enter your name : Mike      Duffy       NAME = "MIKE DUFFY"     The READ command:     Please enter your name : Mike      Duffy       NAME = "Mike       Duffy" 

Command Procedure Parameters

Just as many DCL commands accept parameters, so too can command procedures. Command procedures can accept up to eight parameters on the DCL command line. These parameters are automatically assigned to pre-defined symbols called P1 through P8.

The following procedure illustrates this point:

     $ !     $ ! PARAM.COM, an example command procedure demonstrating parameters.     $ ! It will echo up to two parameters, and ignore the third and subsequent     $ ! parameters.     $ !     $ if P1 .eqs. "" then $ write sys$output "There are no parameters."     $ !     $ if P1 .nes. "" then $ write sys$output "P1: " + P1     $ if P2 .nes. "" then $ write sys$output "P2: " + P2     $ !     $ if P3 .nes. "" then $ write sys$output "Extra parameters ignored."     $ exit 

When executed, this procedure produces the following:

     $ @PARAM     There are no parameters     $ @PARAM 4     P1: 4     $ @PARAM TWO PARAMETERS     P1: TWO     P2: PARAMETERS     $ @PARAM TOO MANY PARAMETERS     P1: TOO     P2: MANY     Extra parameters ignored.     $ 



Getting Started with OpenVMS(c) A Guide for New Users
Getting Started with OpenVMS: A Guide for New Users (HP Technologies)
ISBN: 1555582796
EAN: 2147483647
Year: 2005
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net