cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: stderr - access violation

From: O'Loughlin, Anthony (MED US) <anthony.oloughlin_at_siemens.com>
Date: Thu, 10 Apr 2008 07:16:20 -0400

I'm running on Windows. Do you think this is windows specific?

Thanks for the code. Tony

-----Original Message-----
From: curl-library-bounces_at_cool.haxx.se
[mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of Guenter Knauf
Sent: Wednesday, April 09, 2008 6:39 PM
To: curl-library_at_cool.haxx.se
Subject: Re: stderr - access violation

Hi,
> 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.

#!perl
# simple test script which uses the Perl5 libcurl bindings.

my $url = $ARGV[0] || 'http://oook.de';

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 ("Easy.pm 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 );
$curl->perform;
my $curl_info = $curl->getinfo(CURLINFO_HTTP_CODE);
my $curl_err = $curl->errbuf;
chomp($content);
chomp($headers);

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

Guenter.

----------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions
and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged or
otherwise confidential information. Unauthorized review, forwarding, printing,
copying, distributing, or using such information is strictly prohibited and may
be unlawful. If you received this message in error, or have reason to believe
you are not authorized to receive it, please promptly delete this message and
notify the sender by e-mail with a copy to Central.SecurityOffice_at_siemens.com

Thank you
Received on 2008-04-10