IPC ::运行超时不起作用

时间:2016-07-20 20:06:25

标签: perl

目标:运行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";

1 个答案:

答案 0 :(得分: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 ],  ...