473,883 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any way to capture stdcout output to memory?

I had asked this in comp.lang.c++ with out any answers that would actually
work, so I'm hoping someone here may know a way.

I am calling C library functions that want to output to stdout. I need to
capture this to memory for use internally inside the program without
modifying the library calls that actually do the output.

This is for the GraphViz libraries and it is the output of dot that I'm
actually trying to capture. I have compiled all the libraries and the dot
exectuable which outputs to stdcout. There is also an option to output to a
file and if someone knows a way of redirecting a FILE* to memory that would
work too. There is an option to output to memory but it is a static buffer
that is WAY too small and is broken anyway. When trying this way I get a
memory error and tracing through the code somewhere deep inside the library
it's attempting to write to a FILE*

If no one knows of a way I will have to write a libary function to do this
and have to delve into the GraphViz libraries and try not to come across the
same bug that the pervious person who was attempting to write to memory
does.

One thing I will do in my attempt is not allocate the memory inside the
library as is currently attempted, but pass in a function pointer to
allocate the memory (that will probably just wrap malloc and/or remalloc).

Any help is appreciated. The GraphViz library is pure C.

--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #1
13 1975
Jim Langston said:
I had asked this in comp.lang.c++ with out any answers that would
actually
work, so I'm hoping someone here may know a way.

I am calling C library functions that want to output to stdout. I need
to capture this to memory for use internally inside the program without
modifying the library calls that actually do the output.
Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all about
it.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #2
Richard Heathfield wrote:
Jim Langston said:
> I had asked this in comp.lang.c++ with out any answers that would
actually
work, so I'm hoping someone here may know a way.

I am calling C library functions that want to output to stdout. I
need to capture this to memory for use internally inside the program
without modifying the library calls that actually do the output.

Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all
about it.
I know about pipes from the OS point of view. The thing is I only one one
process running. My program will be calling the library functions a lot as
it produces it's own data to be worked on, then needs to work on the results
from the library calls that dot uses.

--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #3
Jim Langston said:
Richard Heathfield wrote:
>Jim Langston said:
<snip>
>>>
I am calling C library functions that want to output to stdout. I
need to capture this to memory for use internally inside the program
without modifying the library calls that actually do the output.

Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all
about it.

I know about pipes from the OS point of view. The thing is I only one
[want?]
one process running. My program will be calling the library functions
a lot
as it produces it's own data to be worked on, then needs to work on the
results from the library calls that dot uses.
Then I think you're going to have to resort to some lib-hackery. Sorry.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #4
Richard Heathfield wrote:
Jim Langston said:
>Richard Heathfield wrote:
>>Jim Langston said:
<snip>
>>>>
I am calling C library functions that want to output to stdout. I
need to capture this to memory for use internally inside the
program without modifying the library calls that actually do the
output.

Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all
about it.

I know about pipes from the OS point of view. The thing is I only
one

[want?]
>one process running. My program will be calling the library
functions a lot
as it produces it's own data to be worked on, then needs to work on
the results from the library calls that dot uses.

Then I think you're going to have to resort to some lib-hackery.
Sorry.
I was actually playing around with createpipe and such and trying to get the
code to work when I finally realized I was trying to redirect stdin to
stdout and stdout to stdin. Heh, that would be an endless loop since the
functoin reads from stdin.

I think I might have figured out a way, something like:

functiontocaptu restdout();
functionthatwri testostdout();
functionthtaclo sescapture();

functiontocaptu restdout() would actually have to create a thread and have
stdout redirected to that thread. That thread would then read from the
redirected stdout and throw the data into a buffer.
functiontoclose capture() would end the process.

This seems doable, but now seems OT for this newsgroup and I will start
discuessing the possibilty in microsoft.langu age.vc.language .

Thank you for leading me into the right direction.
--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #5
Jim wrote:
) I know about pipes from the OS point of view. The thing is I only one one
) process running. My program will be calling the library functions a lot as
) it produces it's own data to be worked on, then needs to work on the results
) from the library calls that dot uses.

You can use a pipe from a single process, but only if that pipe buffers
enough data so that your library call won't block on the write to stdout.
If the lib only produces a line at a time that may be possible. Read
your platform's documentation on pipe() and dup2().

You might also conceivably be able to link the 'write' call in the library
to your own function, but that is very platform specific deep black magic.

Otherwise, your best bet is pointing stdout to a file and then reading
from it.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Jun 27 '08 #6
Willem wrote:
Jim wrote:
) I know about pipes from the OS point of view. The thing is I only
one one ) process running. My program will be calling the library
functions a lot as ) it produces it's own data to be worked on, then
needs to work on the results ) from the library calls that dot uses.

You can use a pipe from a single process, but only if that pipe
buffers enough data so that your library call won't block on the
write to stdout.
If the lib only produces a line at a time that may be possible.
That's not going to be possible. On a small sample set of data 215 lines
were produced.
Read your platform's documentation on pipe() and dup2().

You might also conceivably be able to link the 'write' call in the
library
to your own function, but that is very platform specific deep black
magic.
Yeah, very deep black magic. Trying to get something not quite that deep,
but I will if I have too.
Otherwise, your best bet is pointing stdout to a file and then reading
from it.
Unfortunately, I need this to be rather fast and file IO being a major
bottleneck isn't going to work for me. I think I may be able to get away
with running the call itself it it's own process allowing me to redirect the
stdout. Not sure yet.

Thanks.

--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #7
Jim Langston wrote:
>
Richard Heathfield wrote:
Jim Langston said:
[...]
I am calling C library functions that want to output to stdout. I
need to capture this to memory for use internally inside the program
without modifying the library calls that actually do the output.
Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all
about it.

I know about pipes from the OS point of view. The thing is I only one one
process running. My program will be calling the library functions a lot as
it produces it's own data to be worked on, then needs to work on the results
from the library calls that dot uses.
Then you'll need to resort to some further OT-for-clc method, such
as connecting stdout to a pipe, and creating a thread to read the
other side of the pipe.

How to do this is very OT here, but may be topical for something like
comp.unix.progr ammer.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Jun 27 '08 #8
Jim Langston wrote:
Richard Heathfield wrote:
>Jim Langston said:
>> I had asked this in comp.lang.c++ with out any answers that would
actually
work, so I'm hoping someone here may know a way.

I am calling C library functions that want to output to stdout. I
need to capture this to memory for use internally inside the program
without modifying the library calls that actually do the output.
Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I'll bet you that comp.unix.progr ammer will know all
about it.

I know about pipes from the OS point of view. The thing is I only one one
process running. My program will be calling the library functions a lot as
it produces it's own data to be worked on, then needs to work on the results
from the library calls that dot uses.
Not standard C, but you can diddle the file descriptors using dup2(),
saving the old FD and switching it back when you are done.
--
clvrmnky <mailto:sp***** *@clevermonkey. org>

Direct replies to this address will be blacklisted. Replace "spamtrap"
with my name to contact me directly.
Jun 27 '08 #9
Jim Langston wrote:
>
I had asked this in comp.lang.c++ with out any answers that would
actually work, so I'm hoping someone here may know a way.

I am calling C library functions that want to output to stdout.
I need to capture this to memory for use internally inside the
program without modifying the library calls that actually do the
output.
All the functions that output to stdout do so as if the final
output is implemented by "putc(i, stdout)". So all you have to do
is write replacement functions, such as, say, "dputs(char *)". It
will call both putc and your own putcm. putcm stuffs the char copy
in the memory buffer. Then modify your source to call the new
functions in place of the old.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2727
by: Jay Donnell | last post by:
I have a function that is a few thousand lines of code (I didn't write it) and I want to capture the output and save it as a variable. This is very easy to do in php. It would look something like this. <?php function myFunc(){ echo "something else" }
0
2259
by: Kevin | last post by:
Configuration: Redhat AS 3.0 IBM DB2 8.1 fixpak 5 Problem: I am attempting to start a capture and get the following error message: 2004-06-10-10.46.34.625103 <Asnenv:setEnvIpcQRcvHdl> ASN8009D "Capture" : "ASN" : Could not get IPC queue with key(s) "(0x300542c4,
0
1044
by: wolfram.wagner | last post by:
Hello group, I have to care about a large replication setup (64 server, 150 laptops). On one of my servers I have a honest problem: Capture in WARMNS is constantly increasing the memory consumption until the machine starts to swap into virtual memory. I guess it is a memory leak. I have tried to reset replication by deleting the synchpoints or Capture cold start. Nothing helped. Trace shows that the system seems to be rebuilding a...
3
4331
by: Juan Crespo | last post by:
Dear Sirs: My name is Juan Crespo and I write you from Spain, I work as application developer in Industrial Automation in Spain. We have as customer a company that wants to reuse old computers for certain vision applications. The computers have a ASUS AGP-V385GX2 video capture card. I develop my applications in National Instruments LabWindows/CVI (C language Development Environment used in engineering applications) So I am searching...
5
8064
by: Lee Gillie | last post by:
I am using Cryptography. You can encrypt or decrypt by providing an output stream as a parameter to the CryptoStream constructor. But I need byte arrays, as I am encrypting on the fly to a socket, and need to manage all socket traffic. My thought was a stateful call to my own Encrypt and Decrypt routines. That I would pass a MemoryStream to the CryptoStream constructor. But it appears that for each write CryptoStream does to my memory...
4
3375
by: jxiang | last post by:
I created a child form that is much bigger than the MDI form in VB.Net. I am trying to capture the whole child form and save as an image or sent to printer. I tried to use BitBlt to capture the child form but I can only capture the visible part of the child form whatever you scroll to any part of the form. I have read the article in site http://www.fengyuan.com/article/wmprint.html unforturely it is for C++ instead of VB.Net. I tried to...
5
7180
by: Muffin | last post by:
I am trying to capture the out put of a command line program. Let say ping or maybe better yet nslookup. I would like to launch and then capture all the output , redirect it I guess to a string variable or something. I know how to start it , but not how to capture it. Nslookup I realize can be started interactively, which is to some degree what I may need to do as I am discovering that there is no easy way to query DNS svr records with...
10
17716
by: lalnamar | last post by:
I want to execute a unix time command using perl, and capture the output (specifically, the time it takes the command to execute). i tried using the system command: system("time command "); however, when i try to capture the output, the capture output does not contain the amount of time it took to execute when i try to do: $var = `time command `; there is the same problem (the ouput from the command is saved in the variable; however,...
2
3105
by: jdbartlett | last post by:
I'm trying to capture output from a command line utility (XMLSec), but only get an empty result. If I call the script from the command line, I see XMLSec's output, but I can't seem to capture it! My PHP installation is working correctly and captures other command line output just fine, XMLSec is the only exception I've found. I've also tried a couple of other systems to confirm this behavior. Capture methods I've tried include:
0
11114
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...
0
10730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10835
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
9563
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...
1
7960
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
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
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
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.