有什么方法可以将stdcout输出捕获到内存中? [英] Any way to capture stdcout output to memory?

查看:80
本文介绍了有什么方法可以将stdcout输出捕获到内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在comp.lang.c ++中问了这个问题,但实际上没有任何答案可以实现,所以我希望这里有人知道。

我正在调用想要输出到stdout的C库函数。我需要将
捕获到内存中,以便在程序内部使用,而不需要修改实际执行输出的库调用。


这是针对GraphViz库的,它是dot的输出,我实际上是想要捕获的.b $ b。我编译了所有库和点

exectuable,它输出到stdcout。还有一个输出到

文件的选项,如果有人知道将FILE *重定向到内存的方式,那么也可以使用
。有一个输出到内存的选项,但它是一个静态缓冲区

,它太小而且无论如何都会被打破。尝试这种方式时,我得到一个

内存错误,并在库内深处的代码中进行跟踪

它正在尝试写入文件*


如果没有人知道某种方法,我将不得不编写一个libary函数来执行此操作

并且必须深入研究GraphViz库并尽量不要遇到

同样的错误,那个试图写入记忆的上一个人

确实如此。


我将尝试做的一件事不是像当前尝试的那样在

库中分配内存,而是将函数指针传递给

分配内存(可能只包装malloc和/或remalloc) )。


任何帮助表示赞赏。 GraphViz库是纯粹的C.


-

Jim Langston
ta ******* @ rocketmail.com

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*******@rocketmail.com

推荐答案

Jim Langston说:
Jim Langston said:

我在comp.lang.c ++中问了这个问题,而且任何答案都会实际上是

工作,所以我希望有人在这里可能知道。


我正在调用想要输出到stdout的C库函数。我需要

将其捕获到内存中,以便在程序内部使用,而不需要修改实际执行输出的库调用。
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.



当然这听起来像管道的工作?不是标准的C概念,

授予,但我敢打赌你comp.unix.programmer会知道所有关于

它。

-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Surely this sounds like a job for a pipe? Not a standard C concept,
granted, but I''ll bet you that comp.unix.programmer 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


Richard Heathfield写道:
Richard Heathfield wrote:

Jim Langston说:
Jim Langston said:

>我在comp.lang.c ++中已经问过这个实际上没有任何答案的答案,所以我希望这里有人知道。

我是调用想要输出到stdout的C库函数。我需要将其捕获到内存中,以便在程序内部使用
而无需修改实际执行输出的库调用。
> 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.



当然这听起来像管道的工作?不是标准的C概念,

授予,但我敢打赌,comp.unix.programmer将知道所有



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



我从操作系统的角度了解管道。事情是我只有一个人b $ b进程运行。我的程序将调用库函数很多,因为它产生了自己的数据,然后需要处理结果

来自库点使用的电话。


-

Jim Langston
ta ******* @ rocketmail.com


Jim Langston说:
Jim Langston said:

Richard Heathfield写道:
Richard Heathfield wrote:

> Jim Langston说:
>Jim Langston said:



< snip>

<snip>


>>>
我正在调用想要的C库函数输出到stdout。我需要将其捕获到内存中,以便在程序内部使用
而无需修改实际执行输出的库调用。
>>>
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.


这听起来像管道的工作?不是标准的C概念,但是我敢打赌你comp.unix.programmer会知道所有关于它的内容。


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



我从操作系统的角度了解管道。事情是我只有一个


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



[想要?]

[want?]


一个进程正在运行。我的程序将调用库函数

a很多

因为它生成它自己的数据,然后需要处理

来自dot使用的库调用。
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.



然后我认为你将不得不诉诸一些lib-hackery。对不起。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件: -http:// WWW。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

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


这篇关于有什么方法可以将stdcout输出捕获到内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆