digitalmars.D.learn - Grabing C(++) stdout
- Chris (5/5) Jul 23 2014 Short question: how can I grab the stdout written to by C(++),
- Adam D. Ruppe (5/7) Jul 23 2014 If it is another program, try this:
- John Colvin (10/15) Jul 23 2014 I don't think I understand the question. stdout is the same file
- Chris (8/26) Jul 23 2014 It's a small library written in C++. I can either load it
- John Colvin (2/37) Jul 23 2014 What do you mean by "grab"?
- Chris (7/47) Jul 23 2014 Redirect it from stdout to somewhere else. If I do something like
- Chris (7/7) Jul 23 2014 The C++ code does this:
- Martijn Pot (3/10) Jul 23 2014 If it can be done offline, I think you can redirect the console
- FreeSlave (4/11) Jul 23 2014 I've created simple example (for Linux) -
- Chris (6/20) Jul 24 2014 @FreeSlave
- Adam D. Ruppe (3/4) Jul 23 2014 It might be writing to stderr instead of stdout... does anything
- FreeSlave (2/2) Jul 23 2014 It's still unclear. What exactly do you mean my grabbing? Please
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.
Jul 23 2014
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.If it is another program, try this: http://dlang.org/phobos/std_process.html#pipeProcess If you want to grab something written by another part of your same program... I'm not sure.
Jul 23 2014
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
Jul 23 2014
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: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.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
Jul 23 2014
On Wednesday, 23 July 2014 at 15:22:41 UTC, Chris wrote:On Wednesday, 23 July 2014 at 15:12:13 UTC, John Colvin wrote:What do you mean by "grab"?On Wednesday, 23 July 2014 at 14:53:35 UTC, Chris wrote: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.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
Jul 23 2014
On Wednesday, 23 July 2014 at 15:27:23 UTC, John Colvin wrote:On Wednesday, 23 July 2014 at 15:22:41 UTC, Chris wrote:Redirect it from stdout to somewhere else. If I do something like this (based on an admittedly old example) std.c.stdio.freopen("test.txt".ptr, "w+", dout.file); If I have writeln("Bla"); "Bla" is in the text file. But the string from C++ is not in there.On Wednesday, 23 July 2014 at 15:12:13 UTC, John Colvin wrote:What do you mean by "grab"?On Wednesday, 23 July 2014 at 14:53:35 UTC, Chris wrote: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.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
Jul 23 2014
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.
Jul 23 2014
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.
Jul 23 2014
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.
Jul 23 2014
On Wednesday, 23 July 2014 at 16:46:04 UTC, FreeSlave wrote:On Wednesday, 23 July 2014 at 15:35:59 UTC, Chris wrote:FreeSlave Thanks a million, just tried it, this one fixed it for me. My mistake was to use std.stdout instead of std.c.stdio.stdout (I thought they were the same). Next I'll see, if there's a way I can grab it directly without referring to a text file.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.
Jul 24 2014
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?
Jul 23 2014
It's still unclear. What exactly do you mean my grabbing? Please provide some minimal example where the problem occurs.
Jul 23 2014