【问题标题】:IPC::Run timeout doesn't workIPC::运行超时不起作用
【发布时间】:2016-07-20 20:06:25
【问题描述】:

目标:运行 Revit(或任何可执行文件)并在运行时间过长时超时的 Perl 脚本。我已经让它运行 Revit,但似乎无法添加超时或使用带有参数的其他版本的运行 $in $out $err

Windows 环境。

下面是一个有效的“运行”和其他根本不工作的结果,尤其是我想要指定超时的那个。

use IPC::Run qw( run timeout );
my $revitPath = "C:\\Program Files\\Autodesk\\Revit 2016\\Revit.exe"; 

#I think I need quotes because there are spaces in the line
my $revitExe = "\"$revitPath\"";
my @cmd1 = "\"$revitPath\"";
#don't think I need any arguments, just want to start it for now and time out. 
my $in = "";
my ($out, $err);

#Here We're Happy, runs Revit:
run @cmd1;

#All the following:  Not Happy:

#This one just seems to do nothing, no complaints, just does nothing
#----->  This is the main goal.  I want to time out Revit if it runs too long.
run @cmd1, timeout(40000) or die "cat: $?";
#----->

#This one says "file not found: "C:\Program Files\Autodesk\Revit 2016\Revit.exe" at line 16
run \@cmd1;

#This one says 
   #Unexpected SCALAR(0x1d21adc) in harness() parameter 3 at example.pl line 21
   #Unexpected SCALAR(0x1d21acc) in harness() parameter 4 at example.pl line 21
run @cmd1, \$in, \$out, \$err;

#This one says "file not found: "C:\Program Files\Autodesk\Revit 2016\Revit.exe" at line 24
run @cmd1, $in, $out, $err;

print "out: $out\n";
print "err: $err\n";

【问题讨论】:

    标签: perl


    【解决方案1】:

    你告诉它执行一个名为

    的文件
    "C:\Program Files\Autodesk\Revit 2016\Revit.exe"
    

    但文件已命名

    C:\Program Files\Autodesk\Revit 2016\Revit.exe
    

    替换

    my @cmd1 = "\"$revitPath\"";
    run \@cmd1, ...
    

    my @cmd1 = $revitPath;
    run \@cmd1, ...
    

    run [ $revitPath ],  ...
    

    【讨论】:

    • 非常感谢!完全奏效。 (显然是 perl 新手)我会在角落里戴着我的傻帽。
    猜你喜欢
    • 1970-01-01
    • 2016-08-05
    • 2014-02-09
    • 2017-08-07
    • 2018-12-27
    • 2012-05-15
    • 2011-02-21
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多