[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

Redirecting output from C system() call?

» close window

The Question is:

 
Hello.  After searching through previous questions sent to you
and the FAQ's I could find nothing to answer my question.
So here goes.
 
On one line, we need to be able to run an executable in DCL and
have the output redirected to the null device (nl:).  This command
is going to be called from within a C++ program using the system()
function.  We want to redirect the output to NULL because we do
not need to see it.  All we need to do is verify that it runs
correctly and returns a good exit status.
 
For the UNIX machines the lines would be like this:
 
string = /directory/exe -option > /dev/null
system(string);
 
The reason we need a one liner is because our C++ program runs
on multiple platforms, one being VMS, another being UNIX.
Therefore, we would like to keep the platform specific code
down to a minimum.
 
I know what we want to do can be accomplished with a command
file such as:
 
$ define SYS$OUTPUT nl:
$ /directory/exe -option
$ deassign SYS$OUTPUT
 
However, we want to avoid having to dynamically generate
this file from the C++ program and having to an pass argument
to it.  In other words, there is a lot of VMS specific
code.
 
We also know that we can possibly accomplish this using
LIB$SPAWN but this will cause us to generate a lot of VMS
specific code also.
 
I know in V 7.1 there is a new DCL command PIPE.  However,
we are running V 6.2.
 
So, on one line, is there any way to run a command and redirect
it's output to nl:?
 
If not, is there a way to enter multiple commands on one DCL
line, i.e.
 
$ define SYS$OUTPUT nl: ; /directory/exe /option ; deassign SYS$OUTPUT
 
Thanks in advance.
 
 


The Answer is :

 
  The Wizard recommends the use of the LIB$SPAWN routine, rather than
  the C system call.  The C system call is implemented using the
  LIB$SPAWN so the effect is the same, save that LIB$SPAWN allows you
  to explicitly specify the input, output, and error devices.
 
  Obviously, specify the output and error parameters as the NLA0: device.
 
  This code can be easily conditionalized within an #ifdef/#endif block.
 
  Other alternatives would include rather more OpenVMS-specific code,
  such as using a mailbox or other OpenVMS device.
 

answer written or last revised on ( 21-DEC-1998 )

» close window