开发者

Looking for a way to launch a batch file if a particular string exists in a text file

I am looking for a way to launch a batch file if a particular string exists in a text file. For example - i want to check file.txt for the string 'working'. if it exists - i would like to launch a batch开发者_StackOverflow社区 file.


use strict;
use warnings;

open my $fh, '<', $file or die "unable to open '$file' for reading :$!";

while(my $line = <$fh>){
    chomp($line);
    if($line =~ /working/){
       my $result = qx/some.bat/;  # use backtick or system()
       last;
    }
}

close($fh);


You can do something like this:

my $data = do {
    open my $in, "<", "file.txt" or die "Could not open: $!";
    local $/;
    <$in>
};

if($data =~ /working/) {
    system("cmd", "/c batch.cmd");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜