12-Mar-2009

Output redirection

There are a number of ways to redirect the output from the execution of a command procedure on OpenVMS. Let's construct a simple command procedure to produce some output so we can demonstrate them:


$ create demo1.com
$ show users
$ exit
^Z
$

Normally, executing this command procedure outputs the information to your terminal, because logical name SYS$OUTPUT is defined as your terminal (assuming you're logged in interactively). For example:


$ @demo1.com
      OpenVMS User Processes at 12-MAR-2009 21:30:37.65
    Total number of users = 23,  number of processes = 1241

 Username     Node     Interactive  Subprocess   Batch
 JFD        KRAIT             1         2
 SYSTEM     KRAIT             1
(etc)

However, there are a number of ways to redirect the output so it ends up in a file, some methods being far more obscure than others.

We can redefine SYS$OUTPUT:


$ define sys$output output.txt
$ @demo1
$ deassign sys$output
$

We can use the /OUTPUT qualifier of the @ command:


$ @demo1/output=output.txt
$

We can use PIPE (and, interestingly, it's simple to set up a "T" situation to output to multiple places, for example the terminal and a log file):


$ pipe @demo1 > output.txt
$

And finally, we can define SYS$OUTPUT as the first line of the command procedure. This is obscure. Normally, a DEFINE verb without the /USER qualifier must be explicitly deassigned. But in this case, the definition is automatically deassigned when the command procedure exits. In effect, it's similar to using the /OUTPUT qualifier on the execution of the command procedure, except it's permanently coded. The command procedure now becomes:


$ create demo2.com
$ define sys$output output.txt
$ show users
$ exit
^Z

Executing this produces no output on the terminal. All output is saved to output.txt.

Posted at March 12, 2009 9:23 PM
Tag Set:
Comments

Or a variation of @ /output that an be useful when capturing command output from interactive commands...

$ @tt:/output=output.txt
_$ command-whatever
_$ some-other-command
_$ ^Z
$

The output of the commands is captured (in output.txt) for later use.

Posted by: Hoff at March 13, 2009 1:13 PM

Hi,

I would like to make two comments:

1. I recommend to use "$ define/user" because this redirects the output only for the next command and not permanentaly. This could cause troubles/iritations.

2. There is a nice freeware tools called logger that saves all output into a file called session.log. Run on all VMS platforms.

Posted by: Eberhard Heuser at March 13, 2009 10:53 PM

define/user doesn't get you much in front of a command procedure. But at least I understand where you're coming from...

Posted by: Jim Duff at March 13, 2009 11:11 PM

Comments are closed