cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Curl, Perl and error codes

From: Jake Peavy <djstunks_at_gmail.com>
Date: Wed, 20 Aug 2008 14:15:37 -0400

On 8/20/08, Adnane <adnane_at_gmail.com> wrote:
>
> Thanks for the reply.
>

This is likely my last on the topic. Perhaps someone else can help if this
is not sufficient.

The weird thing is that I tried other system commands with qx and they works
> as expected.
>

You should not find it so weird.

Here's a sample of the code:
> #$file is an object representing an XML file
> my $info = "";
> my $info2 = "";
> my $data = "";
> ## These next 2 lines are the ones causing me issues
> $info = qx{/usr/bin/curl -b cookies -c cookies -d
> "user=xxx&password=xxx&switch=Log+In" https://URL/FOLDER/SUBFOLDER/};
> $info2 = qx{/usr/bin/curl -b cookies -c cookies -F File=\@$file
> https://URL/FOLDER/SUBFOLDER/};
> ## Example of system command that works
> $data = qx{date};
> print "INFO: $info\n";
> print "INFO2: $info2\n";
> print "DATA: $data\n";
> The output is:
> curl: (6) Couldn't resolve host 'URL'
> curl: (6) Couldn't resolve host 'URL'
> INFO:
> INFO2:
> DATA: Wed Aug 20 10:13:49 EDT 2008
>
> The problem again is that I want the first 2 lines of the output to be
> assigned to $info and $info2 respectively, but for whatever reason, the curl
> error message is printed on the terminal and nothing is assigned to the
> variables. How can I modify the program to accomplish that goal?
>

$ cat tmp.pl
#!/usr/bin/perl

use strict;
use warnings;

my $stdout = qx{ echo "stdout" };
my $stderr = qx{ echo "stderr" >&2 };

print "stdout: $stdout";
print "stderr: $stderr";

__END__

$ ./tmp.pl
"stderr"
stdout: stdout
stderr:

$

Understand?

-- 
-jp
You know something that would really make me applaud? A guy gets stuck in
quicksand, then sinks, then suddenly comes shooting out, riding on water
skis! How do they do that?!
deepthoughtsbyjackhandy.com

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2008-08-20