468,545 Members | 1,892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

Catching output of system()

I've written a perl cgi script but it's too slow so I need
to rewrite it in C++. The perl script passes parameters to
a search engine on our local filesystem and processes the
results (number of hits, etc.). I've never had to do anything
like this in C++ before and I don't know where to start.
So what is the equivalent in C++ to something like this?

open (RESULTS, "srch -q $word |");

Which is the perl method of opening a handle on the output
of a pipe. I imagine I'd like to use system() but there doesn't
seem to be a way to capture the output of the call. Reading
through similar messages in this group I get the impression
this really can't be done. It seems like I need to pass the
search results to the program through the operating system
(the results are VERY large), i.e., through STDIN. This would
be less convenient since I'd like to package everything up
in one program.

Is this true? Is there not a way to do this?

Jul 22 '05 #1
3 1325
On Fri, 05 Mar 2004 08:02:13 -0800, Arvin Portlock <ap********@hotmail.com>
wrote:
I've written a perl cgi script but it's too slow so I need
to rewrite it in C++. The perl script passes parameters to
a search engine on our local filesystem and processes the
results (number of hits, etc.). I've never had to do anything
like this in C++ before and I don't know where to start.
So what is the equivalent in C++ to something like this?

open (RESULTS, "srch -q $word |");

Which is the perl method of opening a handle on the output
of a pipe. I imagine I'd like to use system() but there doesn't
seem to be a way to capture the output of the call. Reading
through similar messages in this group I get the impression
this really can't be done. It seems like I need to pass the
search results to the program through the operating system
(the results are VERY large), i.e., through STDIN. This would
be less convenient since I'd like to package everything up
in one program.

Is this true? Is there not a way to do this?


This is pretty platform-specific. Let me just suggest you download my
STLFilt package for MSVC (link down in my sig), and examine the source code
file CL.CPP. In it, Thomas Becker crafted some code to do piping between
Win32 processes (one of which just happens to be a Perl interpreter,
actually...). This may give you a leg-up.
Good luck,
-leor
Leor Zolman
BD Software
le**@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
Arvin Portlock wrote:
I've written a perl cgi script but it's too slow so I need
to rewrite it in C++. The perl script passes parameters to
a search engine on our local filesystem and processes the
results (number of hits, etc.). I've never had to do anything
like this in C++ before and I don't know where to start.
So what is the equivalent in C++ to something like this?

open (RESULTS, "srch -q $word |");

Which is the perl method of opening a handle on the output
of a pipe. I imagine I'd like to use system() but there doesn't
seem to be a way to capture the output of the call. Reading
through similar messages in this group I get the impression
this really can't be done. It seems like I need to pass the
search results to the program through the operating system
(the results are VERY large), i.e., through STDIN. This would
be less convenient since I'd like to package everything up
in one program.

Is this true? Is there not a way to do this?


There is no -standard- way of doing this. However, you can use popen
which exists in many systems (_popen in win32). If you're using a
Linux/Unix system then you can implement it as a pipe/fork call and not
use the C stdio at all.

Jul 22 '05 #3
Arvin Portlock wrote:
So what is the equivalent in C++ to something like this?

open (RESULTS, "srch -q $word |"); Which is the perl method of opening a handle on the output
of a pipe.
There isn't one. You are into the platform-specific realm now. If on a
UNIX type system, the popen() function may be what you need. Questions
about that should be addressed to comp.unix.programmer. Otherwise, find
a newsgroup dedicated to your platform and ask there.
I imagine I'd like to use system() but there doesn't
seem to be a way to capture the output of the call.


That's correct.


Brian Rodenborn
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by cmay | last post: by
4 posts views Thread by Ron Vecchi | last post: by
3 posts views Thread by Peter A. Schott | last post: by
42 posts views Thread by thomas.mertes | last post: by
3 posts views Thread by Thomas Jansson | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.