cURL / Mailing Lists / curl-library / Single Mail


Re: stderr - access violation

From: Guenter Knauf <>
Date: Thu, 10 Apr 2008 00:38:55 +0200

> I've looked at the manual for using stderr and verbose. This snippet of
> code creates the file (err.txt). However it is empty and the code access
> violates.

> What I'm I missing? Thanks, Tony
I know this issue; seems that filehandles do not work here....; what OS are you on?
Anyway, you need a write callback to make it working; try the below if that works for you;
if so then all you need to do is to print the vars to your filehandles instead of STDOUT.

# simple test script which uses the Perl5 libcurl bindings.

my $url = $ARGV[0] || '';

use WWW::Curl::Easy;

sub curl_write_callback {
  my ( $data, $pointer ) = @_;
  ${$pointer} .= $data;
  return length($data);

print "Perl Version: $]\n";
print "OS Version : $^O\n\n";

printf (" Version: %s\n", $WWW::Curl::Easy::VERSION);
printf ("libcurl Version: %s\n\n", WWW::Curl::easy::version());

print ("=" x 78 . "\n");

my $content;
my $headers;

my $curl = new WWW::Curl::Easy;
$curl->setopt( CURLOPT_FILE, \$content );
$curl->setopt( CURLOPT_HEADERFUNCTION, \&curl_write_callback );
$curl->setopt( CURLOPT_URL, $url );
$curl->setopt( CURLOPT_WRITEFUNCTION, \&curl_write_callback );
$curl->setopt( CURLOPT_WRITEHEADER, \$headers );
my $curl_info = $curl->getinfo(CURLINFO_HTTP_CODE);
my $curl_err = $curl->errbuf;

print "${headers}\n";
print ("=" x 78 . "\n");
print "${content}\n";
print ("=" x 78 . "\n");
print "${curl_info}\n";
print ("=" x 78 . "\n");
print "${curl_err}\n" if ($err);

Received on 2008-04-10