Re: ISO: What is the "best practice" for getting error info from a pipeline?
- From: xhoster@xxxxxxxxx
- Date: 24 Aug 2007 16:48:04 GMT
"Larry W. Virden" <lvirden@xxxxxxxxx> wrote:
# 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
You might be able to hack IO::Pipe to do this, but it would be better
to use something else altogether.
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.
Normally what psend prints to stderr will end up on Perl's STDERR, so
if you log that you will have psend's error in your log file. If you want
better granularity and control then that, you could use IPC::Open3 or
IPC::Run
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.
IO::Pipe and IO::Handle are very general tools. They can't be all
things to all people. You want something specifically from running
external commands.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- ISO: What is the "best practice" for getting error info from a pipeline?
- From: Larry W. Virden
- ISO: What is the "best practice" for getting error info from a pipeline?
- Prev by Date: Re: dynamic regex
- Next by Date: Re: dynamic regex
- Previous by thread: Re: ISO: What is the "best practice" for getting error info from a pipeline?
- Next by thread: better hachage
- Index(es):
Relevant Pages
|