To expound further on the virtues of "system" check out
Programming Perl for documentation of the system
function. There is a code snippet for interpreting various
possibilities including signals and coredumps on a UNIX
system. I used the snippet and made a subroutine called
sysub:
function sysub {
my $cmd = shift;
my $rc = 0xffff & system $cmd;
if ($rc == 0xffff) {
print "command failed: $!\n";
} elsif ($rc > 0x80) {
$rc >>= 8;
print "ran with nonzero exit status $rc\n";
} elsif ($rc != 0) {
print "ran with ";
if ($rc & 0x80) {
$rc &= ~0x80;
print "coredump from ";
}
print "signal $rc\n";
}
return ($rc != 0);
}
a sample invocation:
&sysub ("cp $source $target");
Unfortunately, I never researched the reasoning behind
all the bit-twiddling but it has served me well for several
years. I would appreciate enlightenment from more advanced
monks on this aspect of the code. Also, any suggestions
or improvements would be welcomed.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.