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");
}
精彩评论