Title: Re: execution of shell commands in Perl Scripts
try:

@grep_results = qx{ grep 'abc' ./* };
$grep_status = $?;

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 = "grep 'abc' ./*";
$status = 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.

Neelay.


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.

Reply via email to