By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

Trouble with networking in c++

P: n/a
I'm writing a cgi application in c++ that will run server side in
apache and I'm having a bit of trouble. Basically I'm trying to get
the program to download the html from another site and store that html
in a variable so I can parse it.

I've tried using libcurl, but it exits strangely. And I've tried
running other programs like wget using the system() command, but as far
as I know there is no way to capture the html wget downloads before it
outputs it to a file. I could read it from the file wget creates, but
that would be slow.

I'd appreciate any help I can get. Thanks.

Oct 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

genericd...@gmail.com wrote:
I'm writing a cgi application in c++ that will run server side in
apache and I'm having a bit of trouble. Basically I'm trying to get
the program to download the html from another site and store that html
in a variable so I can parse it.

I've tried using libcurl, but it exits strangely. And I've tried
running other programs like wget using the system() command, but as far
as I know there is no way to capture the html wget downloads before it
outputs it to a file. I could read it from the file wget creates, but
that would be slow.

I'd appreciate any help I can get. Thanks.
What's your question about the C++ language? ( That's what we talk
about in this newsgroup. )

Oct 3 '06 #2

P: n/a
Would it be possible to capture the output from a program that I call
on the command line? For example when I call:

system("curl.exe somewebsite.com");

it displays the html on the the command line, but I can't figure out
how to store this output in a variable. Is this even possible?

Oh and sorry if this is the wrong place for this.

Oct 3 '06 #3

P: n/a

genericd...@gmail.com wrote:
Would it be possible to capture the output from a program that I call
on the command line? For example when I call:

system("curl.exe somewebsite.com");

it displays the html on the the command line, but I can't figure out
how to store this output in a variable. Is this even possible?

Oh and sorry if this is the wrong place for this.
This is off topic here, but I'd suggest that you learn about libcurl
and understand the error that it was giving. Anything that you do with
system() will be system dependant and not portable. Personally, I have
used libcurl to do what you're trying to do, so I know it can be done.

-Brian

Oct 3 '06 #4

P: n/a
Thanks for that

Oct 3 '06 #5

P: n/a
ge*********@gmail.com wrote:
Would it be possible to capture the output from a program that I call
on the command line? For example when I call:

system("curl.exe somewebsite.com");

it displays the html on the the command line, but I can't figure out
how to store this output in a variable. Is this even possible?
It is possible but not directly. One way is to redirect the output from
your system call into a file, then open that file normally... something
like (untested):

system("curl.exe somewebsite.com temp_file");
std::ifstream in_file("temp_file");

This is assuming that your environment supports redirecting output like
that (many do).

[OT]
If you want to do it directly without creating a temporary file, I've
heard there is a function called popen() that may do what you want, but
this is a platform-specific function, so you'll have to ask about that
somewhere where it would be topical.
[/OT]

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Oct 3 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.