0

私は次のことをしています:

#!/usr/bin/perl  
use strict;  
use warnings;  

my $proc = `ps -ef|grep -c myscriptname`;  
print $proc;  

これをスクリプト内で実行すると、2 が出力されます。

ps -ef|grep -c myscriptnameコマンドラインで次のように表示されます:1
なぜですか?

同じmy $proc = qx/ps -ef|grep -c myscriptname/

更新
明確にするために、このスニペットをから実行しますsomerandomscript.pl

更新 2
edorqui のアドバイスに従って、次の取得を削除-cします。

12013 15777 15776 0 14:11 pts/6 00:00:00 sh -c ps -ef | grep myscriptname   
12013 15779 15777 0 14:11 pts/6 00:00:00 grep myscriptname Argument "12013 15777 15776 0 14:11 pts/6 00:00:00 sh -c ps..." isn't numeric in numeric gt (>) at somerandomscript.pl line 8  

スクリプトの中から

4

4 に答える 4

1

あなたのPerlスクリプトの名前は「myscriptname」だと思います。

このスクリプトを実行すると、新しいプロセス (perl myscriptname.pl) が作成され、ps -ef コマンドによって表示されます。もう1つはgrepコマンドに関連しています(探しているテキストがあります)

于 2013-08-09T11:57:09.110 に答える
0

Take a look at the pgrep and the pkill commands. These are standard Linux commands are are way easier to use than trying to do a ps and then a grep.

Also, if you do use ps, take a look at the -o options. These let you display the columns you want, and give you a way to strip out the heading.

于 2013-08-09T14:05:08.857 に答える