【问题标题】:Perl command not being executed as part of a scriptPerl 命令未作为脚本的一部分执行
【发布时间】:2015-08-24 22:24:26
【问题描述】:

我有一个 Perl 脚本 wrapper.pl,其中有一段代码如下所示:

if (-e "$run_dir/fd3d/VrtMsgBus.txt") {

    print "VRTMSGBUS: non scalablity mode VrtMsgBus.txt exists\n";  


    $conf->{'script_list'}{'vrt_scalability'} = {
        'cmd'       => "perl $script_dir/hevc_enc/pak_rtl/vrt_scalability.pl $run_dir $hevc_fd3d_dir $script_dir",
        'dumpdir'   => $dumpdir,
        'units'     => [qw(hwm hle vne hvd hsse hit hpo hfq hft hpr hrs hlc hmc hpp hed vnc htq hsao hmx hlf)],
        'requires'  => [qw(vrtmsgbus mv_vrtmsgbus mv_vrtmsgbus_org mv_vrtmsgbus_no_scalability)],
    };
}
else {

    print "VRTMSGBUS: scalablity mode, VrtMsgBus.txt doesnt exist\n";

    $conf->{'script_list'}{'vrt_scalability_2'} = {
        'cmd'       => "perl $script_dir/hevc_enc/pak_rtl/vrt_scalability.pl $run_dir $hevc_fd3d_dir $script_dir",
        'dumpdir'   => $dumpdir,
        'units'     => [qw(hwm hle vne hvd hsse hit hpo hfq hft hpr hrs hlc hmc hpp hed vnc htq hsao hmx hlf)],
    };


}   

我正在尝试以代码中显示的方式针对不同的条件执行特定的脚本vrt_scalability.plvrt_scalability.p' 是一个单独的脚本,可以从命令行运行,但是当我尝试使用此 wrapper.pl 执行它时,它失败了。如何调试这种代码?

此外,当我独立于wrapper.pl 运行这些代码的cmd 部分中调用的命令时,它们都可以正常工作。我可能做错了什么?

在此处执行脚本:

sub ExecScripts {

   foreach my $exec_script_name (keys %{$conf->{'exec_list'}})
    {

    $conf->{'exec_list'}{$exec_script_name}{'script_was_executed'} = 0;

}

foreach my $exec_script_name (keys %{$conf->{'exec_list'}})
{

    my $dependency_script = $conf->{'exec_list'}{$exec_script_name};
    if (exists $dependency_script->{'requires'})
    {
        foreach my $parent_script (@{$dependency_script->{'requires'}})
        {

            ExecDependencyScripts($conf, $parent_script);
        }
    }  

【问题讨论】:

  • 您不会从这段代码中运行任何东西——您只需修改$conf 结构。还有比这更多的吗?
  • 当你说它失败时。你得到一个错误,它没有运行吗?你怎么知道它失败了?
  • @Borodin..我已经在执行脚本的地方添加了代码。 (代码附加到上面的原始帖子)。谢谢。
  • @ChrisDoyle..我知道它失败了,因为我的脚本“Vrt_scalability.pl”在调用/执行时没有生成它应该生成的转储。作为一个独立的脚本,它('vrt_scalability.pl')可以完美地生成这些转储。
  • 请查看如何创建 MCVE (How to create a Minimal, Complete, and Verifiable Example?) 或 SSCCE (Short, Self-Contained, Correct Example) — 相同基本思想的两个名称和链接。我查看了代码,并认为它比我目前没有时间理解的更复杂(我应该做其他事情)。我怀疑通过将代码缩减为 MCVE 时要小心谨慎,您可以自己解决问题,也可以让 SO 上的人轻松帮助您。

标签: perl debugging hash command scripting-language


【解决方案1】:

您正在填充$conf->{script_list},但后来使用$conf->{exec_list}

如何调试?我经常使用https://metacpan.org/pod/Data::Dumperhttps://metacpan.org/pod/Log::Log4perl::Tiny的组合(无耻插件),并在代码中添加调试语句只是为了确定每一步发生了什么。

在这种情况下,例如,我会在输入 ExecScripts 时添加整个 $conf 变量的打印输出。

【讨论】:

    猜你喜欢
    • 2012-10-20
    • 1970-01-01
    • 2011-05-31
    • 2012-07-21
    • 2015-10-30
    • 2012-03-29
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多