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



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



Relevant Pages

  • Re: check for drive letter before copying files.
    ... Sorry - the EXIT was pseudocode - what you need to do there is either delete the "EXIT" and let the logic take over, or add some sort of jump or Return out of the entire routine. ... script newbie here and i am banging my head against my keyboard trying ... Dim objfso, msg, i ...
    (microsoft.public.scripting.vbscript)
  • Re: Extracting information from a sub-menu
    ... if you put the three lines (select, dir, exit) in a file and redirect ... Message Log (MSG) Viewer ... msgview is an interactive program. ...
    (comp.unix.shell)
  • Re: Extracting information from a sub-menu
    ... Does your msgview produce output on stdout? ... if you put the three lines (select, dir, exit) in a file and redirect ... Message Log (MSG) Viewer ...
    (comp.unix.shell)
  • Re: Newbie.......Python and Networking
    ... code) and then try for routing and firewall scripts for linux, yepp that would be really tough but why not give it a try, i am going to have my vacations for like 13 days so will be preparing for my CCNA and also learning python in that duration. ... It has 2 threads, listener and sender. ... print 'To exit, enter exit' ... msg = raw_input ...
    (comp.lang.python)
  • Re: Error messages
    ... CString::FormatV will be handy for formatting the argument lists. ... I wrote a class that manage the error messages. ... The bs is a struct where I store the msg if the user would like to use ...
    (microsoft.public.vc.mfc)