ISO: What is the "best practice" for getting error info from a pipeline?



Background:

On a scale of 0 to 10, where a person at 0 says "what's a programming
language" and a 10 is Larry Wall, I would rate myself a 2 or maybe a 3
in relationship to perl.

I provide maintenance support on a huge number of programs, written in
a dozen or so languages. I don't do much original programming, so
there is little practice.

In the thousands of files that I support is a rather largish (in the
200+k lines of code range) system that deals with installation
metadata (where does item version 1.2 get installed, with what
permissions, what mode, etc. - that kind of metadata).

Within this code is some perl code that does basically this sort of
thing:

# Email request
my $send = IO::Pipe->new();
my $arch = `/bin/arch`;
chomp $arch;
$send->writer("/path/bin/$arch/psend", 'REQUEST');
my $a = $self->{'queue'};
for (my $indx = 0; $indx < @{$a}; $indx++) {
my $r = $a->[$indx];
$send->print(":$r->[0]");
for (my $args = 1; $args < @{$r}; $args++) {
(my $arg = $r->[$args]) =~ s!([\\"])!\\$1!g;
$send->print(',"', $arg, '"');
}
$send->print("\n");
}
if ($send->close()) {
my $msg = @{$a};
delete $self->{'queue'};
$self->{'queue'} = [ $sys ];
return "$msg steps submitted";
}
$self->error('error: psend failed');
return undef;

The problem is that psend turns out to possibly exit with a non-zero
exit code if it has problems, and this calling program doesn't appear
to notice the fact that psend has failed.

So I have been asked to update it to :

a. recognize that the program at the end of the IO::Pipe has failed
and to exit with an error msg
b. pass any stderr messages back as part of the psend failed error
message, so that the user has some chance of fixing the problem.

In reading the IO::Pipe and IO::Handle docs, I don't see a lot of
detail about handling the remote program's error "exits".

Does anyone have suggestions on what needs to happen? For instance,
the info in IO::Handle mentions $self->error, but says that it is a
boolean indicator; that doesn't seem like it is going to help me with
accessing the error messages theirselves. I suppose the specific exit
code won't be as big a deal as long as the error messages are unique.

Anyways, I'd love any pointers, etc. that you might have. I did google
for some things and tried to solve this, but failed to turn up
anything that looked remotely useful.

.



Relevant Pages

  • Re: Shifting error codes
    ... and related macros available inside a perl script. ... result of pressure from the VMS people (VMS has W*, but doesn't use exit ... to fix perl than to fix all the scripts assuming Unix semantics for $?. ...
    (comp.lang.perl.misc)
  • Re: parsing a variable length record from a mixed format file
    ... test file isn't 45 chars, ... Please see other people's comments on cleaning up your Perl. ... exit 1;} ... This won't confuse the computer but it sure does ...
    (comp.lang.perl.misc)
  • Re: parsing a variable length record from a mixed format file
    ... test file isn't 45 chars, ... Please see other people's comments on cleaning up your Perl. ... exit 1;} ... This won't confuse the computer but it sure does ...
    (comp.lang.perl.misc)
  • Re: from text file to array in shortest way
    ... message displayed by Perl. ... I think croak is not used by default so error messages may be reported ... Or maybe a die-handler can also do the croaking, ... does exactly the same thing as your while loop but saves a few braces. ...
    (comp.lang.perl.misc)
  • Re: Dat files help "Att James"
    ... >Perl spews error messages for that misspelling. ... First I run it in a Program called Perl Builder ... So if I'm going to use from the command prompt I would use the back ... 1....I have a load of dat files in a folder called users this is in the ...
    (comp.lang.perl.misc)