Results 1 to 5 of 5

Thread: Redirect standard output of external tools

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Redirect standard output of external tools

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Redirect standard output of external tools

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Redirect standard output of external tools

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Redirect standard output of external tools

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Redirect standard output of external tools

    thank you very much for your time and your help.
    I'll investigate more in the direction you suggest!

    Regards
    Annalisa

Similar Threads

  1. Replies: 2
    Last Post: 29th November 2009, 17:22
  2. Replies: 2
    Last Post: 2nd June 2008, 08:45
  3. Replies: 52
    Last Post: 10th December 2006, 14:32
  4. redirection of standard input and output
    By guestgulkan in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2006, 20:30
  5. Replies: 4
    Last Post: 10th May 2006, 22:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.