gpt4 book ai didi

perl - 如何将 Perl 脚本的 stdout 和 stderr 输出重定向到 Windows 上的文件?

转载 作者:行者123 更新时间:2023-11-28 19:51:03 27 4
gpt4 key购买 nike

我试过这个:

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";

最佳答案

WindowsPerl 中存在重定向的普遍问题。

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

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

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

dup()

你需要运行:

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

相反。

关于perl - 如何将 Perl 脚本的 stdout 和 stderr 输出重定向到 Windows 上的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/489699/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com