Deb wrote:
>
> I want to run a command inside a script. From the shell, here's the command:
>
> % ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}'
> 19460
open PS, 'ps -ef |' or die "Cannot open pipe from 'ps -ef' $!";
my $pid;
while ( <PS> ) {
next unless m|/usr/lib/sendmail|;
$pid = ( split )[ 1 ];
last;
}
close PS or die "Cannot close pipe from 'ps -ef' $!";
Or:
my $pid;
for ( `ps -ef` ) {
next unless m|/usr/lib/sendmail|;
$pid = ( split )[ 1 ];
last;
}
Or:
my ( $pid ) = map +( split )[ 1 ], grep m|/usr/lib/sendmail|, `ps -ef`;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>