0

我是 perl 的新手,在执行 wget 请求后,我一直在尝试捕获命令屏幕上显示的消息。wget 是从 perl 脚本内部调用的,但是我捕获它的所有努力都失败了。我尝试过:exec、system、open file、backticks、qx 但没有得到所需的结果。我无法使用 CPAN 安装其他软件包,因此无法使用其他模块。

它看起来像:

#wget http://xxx.broker:8087/brocker-v2/wallet/customerbalance/addon_id/xxxxx/country_id/oml/msisdn/xxxxx/pin/xxxx/

屏幕上的反应是这样的:

连接到服务器....
一些响应和详细信息在这里
响应 ok 200

以上几行是我想在变量或文件中捕获的内容。

我尝试过的一些事情:

@wget_response = qx($wget_command);

($stdout, $stderr, $exit) = capture {
 system( $wget_command, @wget_resp );
};

open (my $my_file, '>', 'wget_response') or die "Could not open file: $!";
my $output = `$wget_command`;
die "$!" if $?;
print $my_file $output;
4

1 回答 1

0

正如我在评论中所说,尝试使用 wget 命令重定向 stderr,因此以 my $output 开头的行将变为: my $output = $wget_command 2>&1;

那应该得到变量中的所有输出。

于 2013-10-29T15:33:45.897 回答