Amit
asked on
find a word and then execute a batch file
Hi I want to create a perl script that will look for a word "hello" or sentence "could not find" and if these two things are not found in the file then execute a dos batch file "web.bat".
However if found then it will write the entire line where it found the word "hello" in a file helloout.txt. Please help, I am a newbie to perl and my job requires creation of scripts for automated testing
However if found then it will write the entire line where it found the word "hello" in a file helloout.txt. Please help, I am a newbie to perl and my job requires creation of scripts for automated testing
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't change the file name , I guess. But I need to pass the file name as an argument
#!/usr/bin/perl
my $found;
while( <> ){
if( /\bhello\b/i || /\bcould not find\b/i ){
print;
$found++;
}
}
system("web.bat") unless $found;
my $found;
while( <> ){
if( /\bhello\b/i || /\bcould not find\b/i ){
print;
$found++;
}
}
system("web.bat") unless $found;
#!/usr/bin/perl
my $found;
open O,">>helloout.txt" or die "helloout.txt $!";
while( <> ){
if( /\bhello\b/i || /\bcould not find\b/i ){
print O $_ if /\bhello\b/i ;
$found++;
}
}
close(O) ;
system("web.bat") unless $found;
my $found;
open O,">>helloout.txt" or die "helloout.txt $!";
while( <> ){
if( /\bhello\b/i || /\bcould not find\b/i ){
print O $_ if /\bhello\b/i ;
$found++;
}
}
close(O) ;
system("web.bat") unless $found;
ASKER
It currently appends to the helloout file if the file is existing can we modify it to write again instead of appending whenever the program is run. One last thing can we modify it for finding the word java.lang.exception
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Then I went to that directory ans did
perl test.pl testfile.html
and this is the output I get "Can't open file No such file or directory at test.pl line 1"
something wrong with the code you sent