我下面有这段 perl 代码,主要是想遍历这两个文件。然后调用 bash 脚本(它将文件和定界符作为参数并打印出多行),然后将该命令的所有输出保存到一个新文件中(文件名末尾加上“_processed”)。 以下语法有什么问题(目前它只是创建一个空白文件)?
#!/usr/bin/env perl
use strict;
use warnings;
my(@files) = (
"fixedtt.txt '|'",
"delimd2iffpipe.dat '|'"
);
for my $i (0 .. $#files) {
my($filename) = split /[\s]+/, "$files[$i]", 2;
my($name, $type) = split /[\.]+/, "$filename", 2;
open (MYFILE, '>'."$name".'_processed.'."$type");
system("sh myBashScript.sh $files[$i]"); #I want to write the entire output of this command to a file
close (MYFILE);
}
最佳答案
您可以通过在终端命令前加上> <file name>
来重定向终端命令的输出。 .因此:
system("sh myBashScript.sh $files[$i]");
变成:
system("sh myBashScript.sh $files[$i] > file.txt");
关于linux - perl - 将系统命令重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691915/