2016-07-20 106 views
0

目标:运行Revit(或任何可执行文件)的Perl脚本以及运行时间过长的超时。我有它来运行Revit,但似乎无法添加超时或使用其他版本的运行参数$ in $ out $ errIPC ::运行超时不起作用

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

你告诉它执行命名

"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 ], ... 
+0

太谢谢你了!完全合作。 (显然是perl newb)我会在角落里戴上我的帽子。 – MarshAPI