Grabing C(++) stdout

2014-07-23 Thread Chris via Digitalmars-d-learn
Short question: how can I grab the stdout written to by C(++), 
i.e.


C code:

fwrite(...);

std.cstream will be replaced sooner or later.


Re: Grabing C(++) stdout

2014-07-23 Thread John Colvin via Digitalmars-d-learn

On Wednesday, 23 July 2014 at 14:53:35 UTC, Chris wrote:
Short question: how can I grab the stdout written to by C(++), 
i.e.


C code:

fwrite(...);

std.cstream will be replaced sooner or later.


I don't think I understand the question. stdout is the same file 
handle, doesn't matter whether that's using c++'s cout, c's 
stdout in stdio.h or D's std.stdio.stdout



writeln(hello world);

is just short for

stdout.writeln(hello world);


also, if you want c io functions, import core.stdc.stdio;


If you're wanting to grab the output from another process, take a 
look at std.process


Re: Grabing C(++) stdout

2014-07-23 Thread Chris via Digitalmars-d-learn

On Wednesday, 23 July 2014 at 15:12:13 UTC, John Colvin wrote:

On Wednesday, 23 July 2014 at 14:53:35 UTC, Chris wrote:
Short question: how can I grab the stdout written to by C(++), 
i.e.


C code:

fwrite(...);

std.cstream will be replaced sooner or later.


I don't think I understand the question. stdout is the same 
file handle, doesn't matter whether that's using c++'s cout, 
c's stdout in stdio.h or D's std.stdio.stdout



writeln(hello world);

is just short for

stdout.writeln(hello world);


also, if you want c io functions, import core.stdc.stdio;


If you're wanting to grab the output from another process, take 
a look at std.process


It's a small library written in C++. I can either load it 
dynamically or incorporate it into my program. Either way, when 
the C++ part does its job, I can see the correct output in the 
console window, but I cannot grab it. After analyzing the C++ 
code, it seems that it uses fwrite and writes to stdout.


When I grab stdout I only get the output from the D part, not 
from the C++ part.


Re: Grabing C(++) stdout

2014-07-23 Thread Chris via Digitalmars-d-learn

The C++ code does this:

size_t fwrite ( const void * ptr, size_t size, size_t count, FILE 
* stream );

// stream is stdout

and text appears in the console (a string).

I don't how to grab the text that is written to console. I might 
have to redirect it from within the C++ code.




Re: Grabing C(++) stdout

2014-07-23 Thread Martijn Pot via Digitalmars-d-learn

On Wednesday, 23 July 2014 at 15:35:59 UTC, Chris wrote:

The C++ code does this:

size_t fwrite ( const void * ptr, size_t size, size_t count, 
FILE * stream );

// stream is stdout

and text appears in the console (a string).

I don't how to grab the text that is written to console. I 
might have to redirect it from within the C++ code.


If it can be done offline, I think you can redirect the console 
output to a file.


Re: Grabing C(++) stdout

2014-07-23 Thread FreeSlave via Digitalmars-d-learn

On Wednesday, 23 July 2014 at 15:35:59 UTC, Chris wrote:

The C++ code does this:

size_t fwrite ( const void * ptr, size_t size, size_t count, 
FILE * stream );

// stream is stdout

and text appears in the console (a string).

I don't how to grab the text that is written to console. I 
might have to redirect it from within the C++ code.


I've created simple example (for Linux) - 
https://bitbucket.org/FreeSlave/redirect-example/src

It works as expected. Nothing writes to console, but to file.


Re: Grabing C(++) stdout

2014-07-23 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 23 July 2014 at 15:30:53 UTC, Chris wrote:

Redirect it from stdout to somewhere else.


It might be writing to stderr instead of stdout... does anything 
change if you reopen stderr too?