【发布时间】:2015-09-02 13:30:22
【问题描述】:
这个 perl 脚本正在遍历所有目录和子目录,在其中搜索一个名为 RUN 的文件。然后它打开文件并运行文件中写入的第一行。问题是我无法将系统命令的输出重定向到名为error.log 的文件和STDERR 到另一个名为test_file.errorlog 的文件,但没有创建这样的文件。
请注意,如果未找到,则声明所有变量。
find (\&pickup_run,$path_to_search);
### Subroutine for extracting path of directories with RUN FILE PRESENT
sub pickup_run {
if ($File::Find::name =~/RUN/) {
### If RUN file is present , push it into array named run_file_present
push(@run_file_present,$File::Find::name);
}
}
###### Iterate over the array containing paths to directories containing RUN files one by one
foreach my $var (@run_file_present) {
$var =~ s/\//\\/g;
($path_minus_run=$var) =~ s/RUN\b//;
#print "$path_minus_run\n";
my $test_case_name;
($test_case_name=$path_minus_run) =~ s/expression to be replced//g;
chdir "$path_minus_run";
########While iterating over the paths, open each file
open data, "$var";
#####Run the first two lines containing commands
my @lines = <data>;
my $return_code=system (" $lines[0] >error.log 2>test_file.errorlog");
if($return_code) {
print "$test_case_name \t \t FAIL \n";
}
else {
print "$test_case_name \t \t PASS \n";
}
close (data);
}
【问题讨论】:
标签: perl