使用PERL和Win32 :: OLE操作Word文档在命令行上工作,但不能在BuildForge步骤中工作

时间:2016-07-22 20:18:38

标签: perl win32ole buildforge

我有正常运行的PERL脚本,用于更新Word文档。 PERL脚本编码为与MS Office 2003或2007一起使用。 我试图通过BF on进行更新的机器上安装了Office 2003,安装了相应的模板,宏安全设置已更新。

当我运行确切的命令时,我希望BF在命令行上使用,它按预期工作。 当我通过BF步骤运行时,我得到" ***无法在\ servername \ projectname \ bin \ updateVer.pl第94行"打开doc。 (行号是Perl脚本中的croak)。

脚本看起来像这样:

# enable Sanity checking and make the variable names meaningful
use strict;
use warnings;
use English;
use Win32::OLE;

# Gain access to MS Word 'wd' constants
use Win32::OLE::Const ('Microsoft Word');

use FindBin qw($RealDir);

use lib ($RealDir, "$RealDir/..", "$RealDir/../lib");

# include the common and log utilities
use SCCM::Common;
use SCCM::Logs;

# use command line inputs
use Getopt::Long qw(:config auto_abbrev permute ignore_case pass_through);

# set up logs and process logfile options
logOptions(qw(-log now));

my  $bookmark_update_result = "";
my  $update_ref_result = "";

# Get input from user

my  $path;
my  $bookmarkName;
my  $bookmarkValue;
my  $Word;
my  $newWord = 0;

GetOptions("path=s"           => \$path,
       "bookmarkName=s"   => \$bookmarkName,
   "bookmarkValue=s"  => \$bookmarkValue);

unless ( defined($path) ) 
   { croakf "%[Fail] Path and filename of SVD are required\n"; }

unless ( defined($bookmarkName) && defined($bookmarkValue) ) 
   { croakf "%[Fail] bookmarkName and bookmarkValue parameters are both required.\n"; }

# Start Word in a safer way, checking to see if user has it open first.

eval
{
  $Word = Win32::OLE->GetActiveObject('Word.Application');
  if (! $Word)
  {
    $newWord = 1;
    $Word = Win32::OLE->new('Word.Application', 'Quit');
  }
};

croakf "%[Fail] -- unable to start Word Engine: $@\n", Win32::OLE->LastError() if ($@ || ! $Word);

my $dispAlerts = $Word->{'DisplayAlerts'};
$Word->{'DisplayAlerts'} = wdAlertsNone;

if ($newWord)
{
  $Word->{'Visible'} = 0;
}

my $doc = $Word->Documents->Open($path) or
   croakf ("%[Fail] Unable to open doc ", Win32::OLE->LastError() );

脚本的调用方式如下: ccperl \ servername \ projectname \ bin \ updateVer.pl -path" C:\ BuildForgeBuilds \ BFProjectName \ BFProjectName_0177 \ MyDocument.doc" -bookmarkName REV_Baseline -bookmarkValue My_Baseline_10.20.30

我可以指点一下BF说打开我的工作文档可以吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

我删除了'存档'在作业运行的机器上的模板中,BF能够成功运行其作业。

很有趣我可以直接在服务器上使用'存档'在模板上设置的位。但是,嘿,我不再坚持这个了。

感谢任何阅读我的问题的人,甚至考虑过可能出现的问题。