PreviousNext

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 hostname 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-style redirection symbols (<, <<, and >) to redirect standard input or standard output. You can also use the vertical bar (|) symbol to pipe the output through filters such as nroff, sort, or grep.

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 an 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>