OSF DCE Administration Guide--Core Components

Using the DCE Control Program Command Language
Methods for streamlining complex or sophisticated scripts
2.16.1 Running Operating System Commands from a Script
Although the DCE control program is versatile, there are times when you may want your
script to use operating system commands to accomplish some simple (or even not-so-
simple) operation. The exec command provides a way for scripts to perform external
commands by forking a subprocess in which the command executes. The following
example uses the exec command to retrieve the local host name which is then established
as a hostname variable and subsequently used in the script.
dcecp> set hostname [exec hostname]
myhost
dcecp> directory list /.:/hosts/$hostname -simple
cds-clerk cds-server dts-entity profile self
dcecp>
The exec command normally returns the results of the operation performed in the
subprocess. However, you can use UNIX redirection symbols (<, <<, and >) to redirect
standard input or standard output. You can also use the | (vertical bar) to pipe the output
through filters such as nroff, sort,orgrep.
When used alone, the exec command is synchronous, meaning that the external
command completes before the script continues executing. But when a subprocess will
take a long time to complete, for instance when you synchronize directories in a CDS
cell, you can use the exec command with a & (ampersand) to push a subprocess into the
background. The following example uses the exec command to send previously
collected output to a printer. This lets your script continue without having to wait for the
print command to complete.
dcecp> exec lpr output.log &
dcecp>
124243 Tandem Computers Incorporated 2 35