开发者

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

开发者 https://www.devze.com 2023-02-12 00:05 出处:网络
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 b

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

精彩评论

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