-
LIB$SPAWN, system(), Redirect output from c++ program
- Author: Jay Hamilton |
- Date: 31-05-2006 |
- Posted in: comp.os.vms |
- Show original
Hello,
I'm looking for an example of how to redirect the output of a command
passed to LIB$SPAWN or system() into the null device. Any help is
appreciated-
Thanks,
Jay
- Reply by: unknown |
- Date: 31-05-2006 |
- Show original
In article <[EMAIL PROTECTED]>, Jay Hamilton writes:
I'm looking for an example of how to redirect the output of a command
passed to LIB$SPAWN or system() into the null device. Any help is
appreciated-
integer status, lib$spawn
status = lib$spawn ( 'dir',, 'nla0:' )
type *, status
end
- Reply by: Hoff Hoffman |
- Date: 31-05-2006 |
- Show original
[EMAIL PROTECTED] wrote:
In article <[EMAIL PROTECTED]>, Jay Hamilton writes:
I'm looking for an example of how to redirect the output of a command
passed to LIB$SPAWN or system() into the null device. Any help is
appreciated-
integer status, lib$spawn
status = lib$spawn ( 'dir',, 'nla0:' )
type *, status
end
No offense is intended here, but that example is probably not going
to help a C or C++ programmer that's looking for help with a system call
-- C and C++ programmers get to deal more directly with string
descriptors than do programmers in most other languagtes; that's also
one of the usual problems that C folks encounter with cases such as this
one.
The following UNTESTED code should be fairly close to what you need.
#include <descrip.h>
#include <lib$routines.h>
#include <stsdef.h>
#include <ssdef.h>
$DESCRIPTOR( NullDev, "NLA0:" );
$DESCRIPTOR( Command, "Whatever" );
int RetStat;
RetStat = lib$spawn( &Command, NULL, &NullDev );
if ( $VMS_STATUS_SUCCESS( RetStat ))
return RetStat;
There's an example of lib$spawn in SYS$EXAMPLES:*.C, and there are
gazillions of examples at the HP (Natural Language) Search Assistant web
site -- do please see the OpenVMS FAQ for a pointer to NLSA/SA/AskQ
support tool. The FAQ also has a discussion of string descriptors, and
pointers to areas of interest to C/C++ programmers operating on OpenVMS.
- Reply by: Z |
- Date: 01-06-2006 |
- Show original
Jay Hamilton wrote:
I'm looking for an example of how to redirect the output of a command
passed to LIB$SPAWN or system() into the null device. Any help is
appreciated-
#include <stdlib.h>
system("DIR/NOOUTPUT");
-or-
#include <stdlib.h>
system("PIPE ( define sys$output NL: ; define sys$error NL: ; DIR )");
-or- something similar ...
What command(s) are you trying to execute?
- Reply by: Jay Hamilton |
- Date: 01-06-2006 |
- Show original
Thanks to all of the responese so far, this has really been useful. I
am trying to delete using a wildcard:
del /.../Scd_*.*;*
If I pass /.../Scd_*.*;* to the stdio remove(), an "Invalid wildcard"
status is returned back to me. However, I have found that using the
system or lib$spawn will execute as expected. Using system has the
side effect of echoing file not found to the screen, which I want to
avoid. I am also interested in trapping the file not found error.
Up to now I have been able to successfully redirect the output into the
null device and am testing different status codes to find the FNF error
condition.
Thanks,
Jay
- Reply by: unknown |
- Date: 01-06-2006 |
- Show original
In article <[EMAIL PROTECTED]>, Jay Hamilton writes:
Thanks to all of the responese so far, this has really been useful. I
am trying to delete using a wildcard:
del /.../Scd_*.*;*
The normal VMS syntax for a wildcard directory traversal is along
the lines of:
$ DEL [...]scd_*.*;*
If I pass /.../Scd_*.*;* to the stdio remove(), an "Invalid wildcard"
status is returned back to me.
I'm by no means a C run time library expert, but I'd expect
that remove would expect to be passed an individual filename, not
a wildcard and this would apply regardless of operating system.
However, I have found that using the
system or lib$spawn will execute as expected. Using system has the
side effect of echoing file not found to the screen, which I want to
avoid. I am also interested in trapping the file not found error.
One assumes that you have worked around your file name syntax error
then.
If you wish to trap the "file not found" error then you should be
interested in the 7th parameter to lib$spawn. This captures the
completion status of the spawned subprocess. This will contain
the completion status of the last (or only) DCL command executed
in that subprocess. And, in the case of the $ DELETE command,
the completion status of the command will tend to reflect the
worst error encountered while trying to delete from a wildcarded
file specification.
Whether this 32 bit status will give you enough information to
intelligently deal with the situation is, of course, another question.
Up to now I have been able to successfully redirect the output into the
null device and am testing different status codes to find the FNF error
condition.
$ del asdf.*;*
%DELETE-W-SEARCHFAIL, error searching for
EISNER$DRA3:[DECUSERVE_USER.BRIGGS]ASDF.*;*
-RMS-E-FNF, file not found
$ show sym $status
$STATUS == "%X10931238"
Note that VMS status codes are structured. The high order 4 bits are
reserved. The 1 you see there indicates that this particular status
code has already resulted in an error message displayed to standard output.
The remainder of the high order 16 bits is the facility code. In this
case, %x93 indicates that this status code comes from the DELETE utility.
[Hence the %DELETE portion of the printed error message]
The low order 3 bits are the severity. In this case, 0x0 indicates that
this status code is a warning.
[Hence the -W- portion of the printed error message]
The remainder of the low order 16 bits are the exact message identification.
In this case, 0x1238 indicates the "SEARCHFAIL" condition which is
specific to the "DELETE" facility.
This overview is not complete, but may help you in writing code that
properly recognizes the status code. If you want to do things "by the
book", you could check out LIB$MATCH_COND to ensure that your check
for a status code is ignoring what should be ignored and paying attention
to what is important.
- Reply by: Hoff Hoffman |
- Date: 01-06-2006 |
- Show original
Jay Hamilton wrote:
Thanks to all of the responese so far, this has really been useful. I
am trying to delete using a wildcard:
It appears the root problem is the file specification, and I have no
idea what was intended with /.../Scd_*.*.* -- that looks to be a mixture
of both Unix and OpenVMS naming constructs.
Clearly you know of remove(), and that call does work with valid file
specs. Another option -- which expects OpenVMS ODS-2 or ODS-5 names,
and not the attempted guess-what-format-the-caller-provided capabilities
of the C RTL -- is the lib$delete_file OpenVMS LIBRTL routine.
- <script type="text/javascript"> </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>