473,756 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1490
On Fri, 05 Mar 2004 08:02:13 -0800, Arvin Portlock <ap********@hot mail.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.progr ammer. 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
2340
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 of code, when System.Exception seems to get the job done for me. My application is an ASP.Net intranet site. When I catch an exception, I log the stack trace and deal with it, normally by displaying an error
12
6113
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 out of which unmanaged exception //get thrown
4
1380
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 child control prior to it being sent to the browser and wrap all the HTML content in document.write('') JS statements. I'm kind of lost on how to capture the raw HTML content. (for starters :) Any suggestions
4
1274
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 below catches everything. ---------------------------------------------------- string content ""; foreach(Control c in this.Controls) { StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw);
1
3131
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
1804
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 tried just using a catch statement and trying to convert the output to string, but this doesn't always work. I really don't have programs complex enough to do a lot of specific catching at this point - I just want to know: 1. something failed...
1
2307
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; public static int array() {
42
7027
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 type 'long' is used. That way native C speed can be reached. Now I want to experiment with raising a Seed7 exception (which is emulated with setjmp(), longjmp() in C) for integer
3
2396
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 created in the console. The fortran program can take up to 20 minuttes to finish and at the moment the I will first see any output after the fortran program is done. How make my function write the output of the process as it
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.