LIB$SPAWN, system(), Redirect output from c++ program


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

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

[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.

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?

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

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.

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.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值