PDA

View Full Version : Redirect standard output of external tools



nina1983
10th June 2011, 12:58
Dear,

I'm lost.
I menage to redirect successfully the standard output of my c++ code to the QTextEdit belonging to my GUI Application, implementing the class


class QDebugStream : public std::basic_streambuf<char>

and it works fine for the print commands inside my code.
The problem is that my program call also external tools that have their own print messages that are not redirecting to the GUI but still printed on console.

I am thinking that as I did I am just redirecting the calls

std::cout<<
and not in general all the messages to std output.
For example I have a Fortran library that has a C++ interface I'm including in my code. In the fortran code there are the standard printing messages and those message are printed on console and not on my widget. How shall I redirect those?

I hope a make clear the problem.
Do you have any idea on how to solve this problem?

Thanks in advance once again for your help,
Regards
Annalisa

wysota
10th June 2011, 20:59
How are you calling those external tools? You can use QProcess to call them and intercept their output. Then you can do with it whatever you want.

nina1983
14th June 2011, 09:18
Hi, thanks for your reply.
As far as I understood QProcess, I can use it for external tolls that are called as external executable.
I have a library written in Fortran with a C++ interface that I included in my code and use its function in my code... this functions produce outputs that are not redirected to the GUI. Any idea how can I solve the problem? Maybe the problem is it is Fortran code and doesn't have std::cout?

Thanks for your help,
Annalisa

wysota
14th June 2011, 09:24
It surely doesn't have std::cout :) Maybe there is some native API that will help you intercept STDOUT from those libraries but the chances are slim. On a POSIX system you could probably use dup2() and pipe2() to create a pipe from stdout that you could read but I am just guessing.

An alternative is to replace the symbol used by the library to print output to stdout with a custom function that will redirect it elsewhere but this requires knowledge of how the fortran engine works.

nina1983
14th June 2011, 10:09
thank you very much for your time and your help.
I'll investigate more in the direction you suggest!

Regards
Annalisa