This is a multi-part message in MIME format.
--===============2020069771==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C770A5.9593997D"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C770A5.9593997D
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Sorry small correction: You'll still want to wrap the call in an eval
like so:
=20
my $output;
=20
eval {
$output =3D `$cmd 2>&1`;
};
=20
=20
________________________________
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Mike
Crowl
Sent: Tuesday, March 27, 2007 1:22 PM
To: Deane.Rothenmaier@walgreens.com; activeperl@listserv.ActiveState.com
Subject: RE: Questioning wisdom of system() call inside an eval block
=20
The backtick version would look something like:
=20
my $cmd =3D "certutil -f -enterprise -addstore root $cert > NUL";
my $output =3D `$cmd 2>&1`; # output should contain STDOUT and
STDERR
my $returnCode =3D $?; # whatever value the external
process returned
=20
=20
Typically I wrap commands in either some sort of OO-ish package, or in a
function to help hide the implementation details of external commands
from the program. This makes it more portable, especially if someone
has a wild hair and decides to call OS-specific utilities.
=20
________________________________
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Deane.Rothenmaier@walgreens.com
Sent: Tuesday, March 27, 2007 1:00 PM
To: activeperl@listserv.ActiveState.com
Subject: Questioning wisdom of system() call inside an eval block
=20
Perlers, I feel like I know just enough about this to be dangerous, so
I'll put it to you. =20
I'm beginning to suspect a chunk of code isn't doing what I need it to.
I've looked through the perldoc on system(), and that's what really
started me wondering. What I'm not sure about is which way to go to fix
this--especially since it seems to work. Here's the code I'm looking
at:=20
eval {=20
system( "certutil -f -enterprise -addstore root $cert > NUL 2>&1" );=20
};=20
$@ and Carp::croak( "Error installing certificate ($@)" );
where $cert contains the name of a certificate file (foo.cer). Is there
an easier, or cleaner, way of running a program? How, and what, would I
replace in this jumble using backticks--would that be a better way to
go?=20
Thanks to anyone who'll help me make sure I'm DWIM!=20
Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150
"I am but mad north-north-west. When the wind is southerly I know a hawk
from a hand-saw." -- Hamlet (Act II, scene ii)
------_=_NextPart_001_01C770A5.9593997D
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Sorry small correction: =
You’ll
still want to wrap the call in an eval like =
so:
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>my =
$output;
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>eval {
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> =
$output =3D `$cmd =
2>&1`;
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>};
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
size=3D3
face=3D"Times New Roman">
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:
size=3D2
face=3DTahoma>
activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com]
style=3D'font-weight:
bold'>On Behalf Of Mike Crowl
Sent: Tuesday, March 27, =
2007 1:22
PM
To:
Deane.Rothenmaier@walgreens.com; activeperl@listserv.ActiveState.com
Subject: RE: Questioning =
wisdom of
system() call inside an eval block
style=3D'font-size:
12.0pt'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>The backtick version would look =
something
like:
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> my $cmd =3D =
“
size=3D2 face=3D"Courier New">
style=3D'font-size:10.0pt;font-family:"Courier New"'>certutil
-f -enterprise -addstore root $cert > NUL”;
size=3D2
color=3Dnavy face=3DArial>
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> my $output =3D `$cmd
2>&1`; # output should contain =
STDOUT and
STDERR
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'> my $returnCode =3D
$?; &nbs=
p;
# whatever value the external process =
returned
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Typically I wrap commands in either =
some
sort of OO-ish package, or in a function to help hide the implementation
details of external commands from the program. This makes it more =
portable,
especially if someone has a wild hair and decides to call OS-specific
utilities.
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
size=3D3
face=3D"Times New Roman">
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:
size=3D2
face=3DTahoma>
activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com]
style=3D'font-weight:
bold'>On Behalf Of Deane.Rothenmaier@walgreens.com
Sent: Tuesday, March 27, =
2007 1:00
PM
To:
activeperl@listserv.ActiveState.com
Subject: Questioning =
wisdom of
system() call inside an eval block
style=3D'font-size:
12.0pt'>
style=3D'font-size:
12.0pt'>
style=3D'font-size:10.0pt;font-family:
Arial'>Perlers, I feel like I know just enough about this to be =
dangerous, so
I'll put it to you.
style=3D'font-size:10.0pt;font-family:Arial'>I'm
beginning to suspect a chunk of code isn't doing what I need it to. I've =
looked
through the perldoc on system(), and that's what really started me =
wondering.
What I'm not sure about is which way to go to fix this--especially since =
it
seems to work. Here's the code I'm looking at:
style=3D'font-size:10.0pt;font-family:"Courier New"'>eval
{
style=3D'font-size:10.0pt;font-family:"Courier New"'>
system( "certutil -f -enterprise -addstore root $cert > =
NUL
2>&1" );
style=3D'font-size:10.0pt;font-family:"Courier New"'>};
style=3D'font-size:10.0pt;font-family:"Courier New"'>$@
and Carp::croak( "Error installing certificate ($@)" =
);
size=3D2 face=3DArial>
style=3D'font-size:10.0pt;font-family:Arial'>
style=3D'font-size:10.0pt;font-family:Arial'>where
$cert contains the name of a certificate file (foo.cer). Is there =
an
easier, or cleaner, way of running a program? How, and what, would =
I
replace in this jumble using backticks--would that be a better way to =
go?
style=3D'font-size:10.0pt;font-family:Arial'>Thanks
to anyone who'll help me make sure I'm DWIM!
style=3D'font-size:10.0pt;font-family:Arial'>Deane
Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150
"I am but mad north-north-west. When the wind is southerly I know a =
hawk
from a hand-saw." -- Hamlet (Act II, scene =
ii)