无法打开文件perl

时间:2012-10-29 04:42:56

标签: perl xslt libxslt

我正在尝试将plist文件转换为JUnit样式的XML。我有一个xsl样式表,它将plist转换为JUnit / ANT XML。

以下是我将plist转换为XML的perl代码:

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
my $stylesheet = $xslt->parse_stylesheet_file("\\\~/Hudson/build/workspace/ui-automation/automation\\\ test\\\ suite/plist2junit.xsl");

my $counter = 1;
my @plistFiles = glob('Logs/*/*.plist');
foreach (@plistFiles){
    #Escape the file path and specify abosulte path
    my $plistFile = $_;
    $plistFile =~ s/([ ()])/\\$1/g;
    $path2plist = "\\\~/Hudson/build/workspace/ui-automation/automation\\\ test\\\ suite/$plistFile";
    #transform the plist file to xml
    my $source = $parser->parse_file($path2plist);
    my $results = $stylesheet->transform($source);

    my $resultsFile = "\\\~/Hudson/build/workspace/ui-automation/automation\\\ test\\\ suite/JUnit/results$counter.xml";
    #create the output file
    unless(open FILE, '>'.$resultsFile) {
    # Die with error message
    die "\nUnable to create $file\n";
    }

    # Write results to the file.
    $stylesheet->output_file($results, FILE);
    close FILE;
    $counter++;
}

在Hudson / Jenkins上运行perl脚本后,它会输出以下错误消息:

  

无法打开〜/ Hudson / build / workspace / ui-automation / automation \ test \ suite / Logs / Run \ 1 / Automation \ Results.plist:没有这样的   文件或目录

错误是由代码中的my $source = $parser->parse_file($path2plist);引起的。我无法弄清楚为什么它无法找到/读取文件。

任何人都知道可能导致错误的原因是什么?

1 个答案:

答案 0 :(得分:3)

错误消息中提到的路径中有三个明显的错误。

~/Hudson/build/workspace/ui-automation/automation\ test\ suite/Logs/Run\ 1/Automation\ Results.plist

那些是:

  1. 当前目录中没有名为~的目录。也许您打算使用$ENV{HOME}那里的值?
  2. 磁盘上没有名为automation\ test\ suite的目录,但可能有一个名为automation test suite的目录。
  3. 同样,磁盘上没有名为Run\ 1的目录,但可能有一个名为Run 1的目录。
相关问题