找不到传递给使用Perl调用的程序的参数";系统“;命令

找不到传递给使用Perl调用的程序的参数";系统“;命令,perl,command,system,arguments,Perl,Command,System,Arguments,我正在编写一个Perl脚本,在目录中的每个文件上运行一个外部程序。该程序将文件从一种格式转换为另一种格式。事情是这样的 当我从命令行运行程序时,一切正常: computer.name % /path/program /inpath/input.in /outpath/output.out converting: /inpath/input.in to /outpath/output.out computer.name % 下面是我编写的代码,用于转换目录中的所有文件(列在“file\u li

我正在编写一个Perl脚本,在目录中的每个文件上运行一个外部程序。该程序将文件从一种格式转换为另一种格式。事情是这样的

当我从命令行运行程序时,一切正常:

computer.name % /path/program /inpath/input.in /outpath/output.out
converting: /inpath/input.in to /outpath/output.out

computer.name %
下面是我编写的代码,用于转换目录中的所有文件(列在
“file\u list.txt”
中):

我验证了每个文件都在正确的位置,不知道为什么会出现此错误。为什么找不到这些文件?当我使用命令行手动传递参数时,没有问题。当我通过
system
调用通过变量传递参数时,即使路径和文件名正确,也找不到参数

非常感谢您的建议

您的文件列表(
@obs_files
)来自通过
@obs_files=”读取文件

执行此操作时,数组的每个元素都是文件中的一行(例如目录列表),该行以换行符结尾

在使用它之前,您需要通过
chomp($file)
删除换行符


请注意
s/(\*)//g不删除尾随的换行符

没有什么明显的问题。。。。您确定它正在运行的命令是正确的吗?在运行系统之前,我会输出join(“,@arg_list)的结果,并查看将其粘贴到shell中是否具有相同的效果。/path/program是脚本吗?如果是这样,则该系统调用调用$SHELL来执行该命令。如果是这样的话,您的.cshrc/.tcshrc/.bashrc是否会为您的主目录创建一个新的shell chdir?将pwd命令添加到/path/program,以便可以看到当前的工作目录。
#!/usr/bin/perl -w

use warnings;
use diagnostics;
use FileHandle;
use File::Copy;

# Set simulation parameters and directories
@test_dates = ("20110414");
$listfile = "file_list.txt";
$execname = "/path/program";

foreach $date (@test_dates)
{
    # Set/make directories
    $obs_file_dir = "inpath";
    $pred_file_dir = "outpath";
    mkdir "$pred_file_dir", 0755 unless -d "$pred_file_dir";

    # Read input file names to array
    $obs_file_list = $obs_file_dir . $listfile;
    open(DIR, $obs_file_list) or die "Could not open file!";
    @obs_files = <DIR>;
    close(DIR);

    # Convert and save files
    foreach $file (@obs_files)
    {    
        $file =~ s/(\*)//g;
        $infile = $obs_file_dir . $file;
        $outfile = $pred_file_dir . $file;
        $outfile =~ s/in/out/g;
        print $infile . "\n";
        @arg_list = ($execname, $infile, $outfile);
        system(@arg_list);
    }
}
computer.name % perl_script_name.pl
/inpath/input.in
converting: /inpath/input.in to /outpath/output.out

unable to find /inpath/input.in
stat status=-1
error while processing the product