Steve Bertrand wrote:
> Tom Phoenix wrote:
>>
[snip]
>>
I think you're looking for the program's exit status. Traditionally on
Unix and many similar systems, the exit status is an integer, with 0
meaning "normal exit" and anything else meaning that something went
wrong. That's the value that's used by programs that run other
programs (such as the 'make' system utility) and need to know when a
step has failed. In Perl, you can access the exit status with the $?
variable after running a command via system or backticks. Beware: If
your command is run by the shell, you'll get the shell's exit status,
which may not be the exit status you were looking for.
Wow, thank you for such a thoughtful and detailed explanation! I don't
think I've ever run across the $? before (forgive me if it was noted in
the ref, obj, mod book).
Personally, I cringe whenever I see `$command` or system "$command"
inside of anything I have to work on (albeit I have several scripts I've
done this in myself, and still use). Everyone has their own way of
coding, and someone's code always looks worse to someone else. After
all, we are all only learning, no matter what we know...right?
You can also consider capturing the STDERR output of the external
program. Since the exit status doesn't say much, most programs cough
out some last words when something goes wrong. In fact, if the program
outputs anything to STDERR, even if it exited with "success", the
error text may be important news you'd want to treat as a failure. One
common way to capture STDERR when running an external program is with
IPC::Open3.
You are speaking of Unix (under shell) STDERR here, correct?
[snip]
Tom was probably thinking of Unix, but same principles apply to other
platforms.
It's also worth noting that whatever application you're using to update
the database may well output something useful to STDOUT and it may be a
simple strategy to examine this output to determine the status of an
operation. If you assign the result of a backtick string to a scalar
variable
my $status = `command`;
then the entire output of the command will be stored as a single string.
If you assign it to an array
my @status = `command`;
then the output will be stored as one line per array element.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/