![](/img/trans.png)
[英]How to run a script that can only write to STDOUT and read from STDIN?
[英]How to get the stdout from a Test::Script run?
我想用Test :: Script模块测试Perl脚本,例如testme.pl,并获取执行脚本的标准输出。 我得到一个undef
至今。
这是我尝试过的(测试文件test.t
):
use Test::More tests => 2;
use Test::Script;
use Data::Dumper;
script_compiles('testme.pl');
my $out;
script_runs(['testme.pl'], {"stdout"=>$out}, 'run_script');
print "Out is " . Dumper($out);
以及要测试的脚本( testme.pl
)
print "catchme if you can\n";
boris@midkemia artif_get_file $ perl perl_test.pl
1..2
ok 1 - Script testme.pl compiles
ok 2 - run_script
Out is $VAR1 = undef;
我也尝试使用数组ref \\ @out代替$ out,仍然没有运气。 任何想法? 谢谢!
你差不多了。 您需要给stdout
选项提供参考 。 否则,您只是传递undef
,它将忽略该选项。
script_runs(['testme.pl'], {"stdout"=>\$out}, 'run_script');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.