473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 1476
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
4
by: Ron Vecchi | last post by:
I have a custom control which has a child control (PlaceHolder) The placeholder will have any number of child controls added to it. I would like to catch the rendered content of the placeholder...
4
by: Ron Vecchi | last post by:
In the RenderControl() method I have some code which will catch the controls HTML output. But what I'm tring to accomplish is catching only a perticular control and its child controls. The code...
1
by: Atara | last post by:
My application starts with: Module mmcMain Public Sub Main() Debug.WriteLine("Main begin") Dim splashForm As New mcDlgs.cmcDlgSplash2 splashForm.Show() ....
3
by: Peter A. Schott | last post by:
I know there's got to be an easy way to do this - I want a way to catch the error text that would normally be shown in an interactive session and put that value into a string I can use later. I've...
1
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
42
by: thomas.mertes | last post by:
Is it possible to use some C or compiler extension to catch integer overflow? The situation is as follows: I use C as target language for compiled Seed7 programs. For integer computions the C...
3
by: Thomas Jansson | last post by:
Dear all I have tkinkter based frontend to a Fortran based program. I use subprocess to launch the fortran program as a child process and I wish to see the output of the fortran program as it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.