|
|
|
xqt_util
- Shell Execution UtilitiesTo execute a single shell command and to read the output of the command, the following code could be used:
#include "xqt_util.h" -- Shell execution utilities. char buffer[132] ; XqtStream stream ; ... xqtOpen (NULL, &stream) ; ... xqtWrite (stream, "%s", "shell command") ; xqtRead (stream, sizeof buffer, buffer) ; ... process result string in buffer ... xqtClose (stream) ;The code above executes only one command; you can actually have any number of
xqtWrite()
s and xqtRead()
s between the opening
and the closing of the execution stream.
Note that you must have some way of knowing how many lines of output to read from an executed command. One means of ensuring that the correct number of lines is read is as follows:
char filename[256] ; ... xqtWrite (stream, "%s", "DIRECTORY/NOHEADING/NOTRAILING") ; xqtWrite (stream, "%s", "SHOW SYMBOL $STATUS") ; while (!xqtRead (stream, sizeof filename, filename)) { if (strncmp (filename, " $STATUS ==", 12) == 0) break ; ... process file name ... } ... end of directory listing ...DCL's
$STATUS
variable holds the completion status of the last
command executed (the directory command, in this case). The SHOW
SYMBOL $STATUS
command outputs the completion status in the
following format:
$STATUS == "%XcompletionStatus"The completion status is a VMS error code (
SS$_
, etc.)
displayed in hexadecimal form. A useful thing to do is to examine the
value of the $STATUS
variable after every command executed.
UNIX shells generally have a similar means of determining the completion
status of a command.
xqtClose()
- closes a shell execution stream.
xqtFd()
- returns the file descriptor for input from a shell
execution stream.
xqtOpen()
- opens a shell execution stream.
xqtPoll()
- checks if any output from a shell execution
stream is waiting to be read.
xqtRead()
- reads a line of output from a shell execution
stream.
xqtWrite()
- writes a line of input to a shell execution
stream.
xqt_util.c
xqt_util.h
(See libgpl
for the
complete source, including support routines and build files.)