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.exeperl.exedup()perl.exe

次を実行する必要があります。

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

代わりは。

于 2009-01-28T22:50:20.790 に答える
1

すべてのテスト スクリプトで、(stdout を使用する代わりに) テストのレポートとログのオプションを常に構成します。また、出力をリダイレクトするというまったく同じ問題に遭遇しました。上記のソリューションを使用するか、私がしたことを実行できます。

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 スクリプトから Windows 上のファイルにリダイレクトできます。

于 2012-05-15T21:12:35.607 に答える