in reply to I want to capture a programs output AND I want the return status

Why not using the program output as a 'logical return value' ?
(will show you if the program 'worked' and not only if the program excuted correctly...)

For example :
Modify your prog to display 'ok' at the end, if everything is ok.
In the case of a program that you can't modify, a regex matching a typical message for success/correct behaviour will be used.
(obiously no/truncated/incorrect output -> pb)

UPDATE : Thinking twice about it, it sounds a really weird way...
UPDATE2 (after stefan_k and davorg answers): Now that it's clear that it's not the usual (correct?) way to do it
(use of $? is the right answer) could someone spot a flaw/weakness/drawback in my idea ?
And tell me why it's not used more often...

"Only Bad Coders Badly Code In Perl" (OBC2IP)
  • Comment on Re: I want to capture a programs output AND I want the return status

Replies are listed 'Best First'.
Re (tilly) 2: I want to capture a programs output AND I want the return status
by tilly (Archbishop) on Apr 13, 2001 at 03:05 UTC
    Several issues.

    First of all it is different. Unless you control the external utility (which you probably don't because you didn't write it) you cannot make a change like that. And if you do you will confuse everyone else.

    Secondly it is inflexible. There are lots of programs that have legitimate reasons to spit out reams of text that may include an OK in them.

    Thirdly you often want to send a child program's output somewhere else but you still need to capture the return code.

    That answer why your idea is not used more often?