Re: execution of shell commands in Perl Scripts

[email protected] (Jonas B . Nielsen) Fri, 9 Sep 2005 12:25:50 +0200
Newsgroups perl.scripts
Message-ID <[email protected]>
Hello,

If you want to catch the output of a command, use:

$data = qx/$cmd/

The status you where getting back when calling system indicated success 
of your execution with 0.

The return value of 0 is true for shell (mostly), it is platform 
dependent I suppose, so you have to turn you Perl logic around.

Often see Perl scripts end with exit(0); for communication with the 
shell executing the perl script in question.

jonasbn

On 8/9-2005, at 23.42, 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.