Re: execution of shell commands in Perl Scripts
[email protected] (Riehm Stephen) Fri, 09 Sep 2005 11:41:48 +0200
| Newsgroups | perl.scripts |
|---|---|
| Message-ID | <BF47257C.10C57%[email protected]> |
--B_3209110909_520343
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
try:
@grep_results =3D qx{ grep 'abc' ./* };
$grep_status =3D $?;
system is only really usefull for starting programs which then do their =
own
thing. If you want the output, use qx!
Cheers,
Steve
On 08.09.2005 23:42 Uhr, "neelay thaker" wrote:
> Hi,
> I'm trying to use the output of a grep command in a shell script.
> If I do-
> $cmd =3D "grep 'abc' ./*";
> $status =3D system $cmd;
> Then $status always turns out to be 0, even if I use invalid arguments =
with
> grep.
> If the result of grep is not empty, I want to perform some action and =
if it is
> empty, I want to do something else.
> How can I get the output of grep into a string variable in the Perl =
script?
> Any help will be highly appreciated.
> Thanks.
>=20
> Neelay.
>=20
Der Inhalt dieser E-Mail oder eventueller Anhange ist ausschliesslich
fur den bezeichneten Adressaten bestimmt. Wenn Sie nicht der
vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein
sollten, so beachten Sie bitte, dass jede Form der Kenntnisnahme,
Veroffentlichung, Vervielfaltigung oder Weitergabe des Inhalts
dieser E-Mail unzulassig ist. Wir bitten Sie, sich in diesem Fall
mit dem Absender der E-Mail in Verbindung zu setzen.
The information contained in this email is intended solely for
the addressee. If you are not the intended recipient, any form
of disclosure, reproduction, distribution or any action taken
or refrained from in reliance on it, is prohibited and may
be unlawful. Please notify the sender immediately..
--B_3209110909_520343
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<HTML>
<HEAD>
<TITLE>Re: execution of shell commands in Perl Scripts</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Times New Roman"><SPAN STYLE=3D'font-size:14.0px'>try:<BR>
<BR>
@grep_results =3D qx{ grep 'abc' ./* };<BR>
$grep_status =3D $?;<BR>
<BR>
system is only really usefull for starting programs which then do their =
own thing. If you want the output, use qx!<BR>
<BR>
Cheers,<BR>
<BR>
Steve<BR>
<BR>
On 08.09.2005 23:42 Uhr, "neelay thaker" wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE=3D"Times New Roman"><SPAN =
STYLE=3D'font-size:14.0px'>Hi,<BR>
I'm trying to use the output of a grep command in a shell script.<BR>
If I do-<BR>
$cmd =3D "grep 'abc' ./*";<BR>
$status =3D system $cmd;<BR>
Then $status always turns out to be 0, even if I use invalid arguments =
with grep.<BR>
If the result of grep is not empty, I want to perform some action and if =
it is empty, I want to do something else.<BR>
How can I get the output of grep into a string variable in the Perl =
script?<BR>
Any help will be highly appreciated.<BR>
Thanks.<BR>
<BR>
Neelay.<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE=3D"Times New Roman"><SPAN =
STYLE=3D'font-size:14.0px'><BR>
</SPAN></FONT>
</BODY>
<!--[object_id=3D#hse24.de#]--><P align=3Dleft><FONT face=3DTahoma =
size=3D2><FONT color=3D#0000ff>Der Inhalt dieser E-Mail oder eventueller =
Anhange ist ausschliesslich fur den bezeichneten Adressaten bestimmt. =
Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen =
Vertreter sein sollten, so beachten Sie bitte, dass jede Form der =
Kenntnisnahme, Veroffentlichung, Vervielfaltigung oder Weitergabe des =
Inhalts dieser E-Mail unzulassig ist. Wir bitten Sie, sich in diesem =
Fall mit dem Absender der E-Mail in Verbindung zu =
setzen.</FONT></FONT></P>
<P align=3Dleft><FONT face=3DTahoma size=3D2><FONT color=3D#0000ff>The =
information contained in this email is intended solely for the =
addressee. If you are not the intended recipient, any form<BR>of =
disclosure, reproduction, distribution or any action taken or refrained =
from in reliance on it, is prohibited and may<BR>be unlawful. Please =
notify the sender immediately.</FONT></FONT></P></HTML>
--B_3209110909_520343--