4

我试过这个:

test1.pl >output.log 2>&1

但这是结果:

Can't dup STDOUT:  Permission denied at C:/Perl/lib/Test/Builder.pm line 1376.
Compilation failed in require at C:/Perl/lib/Test/Builder/Module.pm line 3.
BEGIN failed--compilation aborted at C:/Perl/lib/Test/Builder/Module.pm line 3.
Compilation failed in require at C:/Perl/lib/Test/More.pm line 22.
BEGIN failed--compilation aborted at C:/Perl/lib/Test/More.pm line 22.
Compilation failed in require at C:/Perl/site/lib/Test/WWW/Selenium.pm line 72.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Test/WWW/Selenium.pm line 72.
Compilation failed in require at C:\Software\selenium-remote-control-1.0-beta-2\tests\test1.pl line 5.
BEGIN failed--compilation aborted at C:\Software\selenium-remote-control-1.0-beta-2\tests\test1.pl line 5.

只要我不尝试以任何方式从命令行重定向输出,脚本就会运行文件。

这是我的脚本,以防万一。(这是一个Selenium测试脚本):

#!C:/perl/bin/perl.exe -w
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost",
                                    port => 4444,
                                    browser => "*chrome",
                                    browser_url => "http://localhost/" );
print "Start Time: " . localtime() . "\n";
for (my $count = 3000; $count > 0; $count--)
{
    print $count . " tests remaining.\n";
    $sel->open_ok("/home");
    $sel->click_ok("link=News");
    $sel->wait_for_page_to_load_ok("30000");
    $sel->click_ok("video");
    $sel->wait_for_page_to_load_ok("30000");
    $sel->click_ok("link=Sports");
    $sel->wait_for_page_to_load_ok("30000");
    $sel->click_ok("link=Movies");
    $sel->wait_for_page_to_load_ok("30000");
    $sel->click_ok("moremovies");
    $sel->wait_for_page_to_load_ok("30000");
}

print "End Time: " . localtime() . "\n";
4

2 回答 2

10

Perlfor中的重定向存在一般问题Windows

包中失败的行Test::More说:

open TESTOUT, ">&STDOUT" or die $!;

当您调用命令时,这将失败test.pl > outlog.log,因为您要重定向STDOUT到的文件被 锁定cmd.exe,而不是被锁定perl.exe。你不能dup()perl.exe

你需要运行:

perl test1.pl >output.log 2>&1

反而。

于 2009-01-28T22:50:20.790 回答
1

在我所有的测试脚本中,我总是配置测试报告和日志记录选项(而不是使用标准输出)。我也遇到了同样的重定向输出问题。您可以使用我上面列出的解决方案,或者您可以做我所做的:

my $res_file = "C:\\Automation\\Results\\Test_Logs\\login_test_output.txt"; 
my $err_file = "C:\\Automation\\Results\\Test_Logs\\login_error_output.txt";

open FH, ">$res_file" or die "couldn't open file: $!";

FH->autoflush(1); # Make FileHandle HOT. Set to 0 to turn autoflush off

Test::More->builder->output (*FH{IO}); # Redirect to test result file ($res_file)
Test::More->builder->failure_output ($err_file); # and test failure output file

使用这种方法,我可以将我的 perl 脚本中的 stdout 和 stderr 输出重定向到 Windows 上的文件。

于 2012-05-15T21:12:35.607 回答