Results 1 to 8 of 8

Thread: QProcess and capturing output

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: QProcess and capturing output

    I thought about that too, but I don't think I'll be able to do what I want to do putting it into a file.

    Ultimately I want to provide a real-time status of the output of the executable that is being run using QProcess. This is the only executable I am having issues with (and unfortunately, one of the key executables I need to get a status from).

    If I try redirecting the output to a file in a command-line window (execute.exe > test.txt) I appear to only get text in it at the end as well... but if I don't redirect it, I get output as I should.

    I am guessing I am fighting with this executable, and likely there isn't a way for me to work around it, but before I give up, I want to make sure that there isn't something else that I can do to.

    Thanks for everyone's suggestions by the way!

  2. #2
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and capturing output

    Hi,

    redirection is normally handled inside a shell, not in an external program.

    cu, Bernd
    --
    redir.cpp:

    Qt Code:
    1. #include <QDebug>
    2. #include <QProcess>
    3.  
    4. int main(void)
    5. {
    6. QProcess qp1, qp2;
    7.  
    8. // does not work, because i/o redirection is handled by a shell, not by QProcess or the external exe
    9. // here the string "> c:\\out1" (!) is passed as an argument to argecho
    10. qp1.start("c:\\uti\\argecho.exe", QStringList() << "> c:\\out1" << "1" << "2" << "3");
    11. qp1.waitForFinished();
    12. qDebug() << "qp1:" << qp1.readAll();
    13.  
    14. // this works (put the redirection before the external command!)
    15. qp2.start("c:\\windows\\system32\\cmd.exe", QStringList() << "/C" << "> c:\\out2" << "c:\\uti\\argecho.exe" << "1" << "2" << "3");
    16. qp2.waitForFinished();
    17. qDebug() << "qp2:" << qp2.readAll();
    18.  
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 

    argecho.c:

    Qt Code:
    1. #include <stdio.h>
    2.  
    3. int main ( int argc, char ** argv )
    4. {
    5. int i;
    6.  
    7. for ( i = 0; i < argc; i++ )
    8. printf( "%d: %s\n", i, argv[i] );
    9.  
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: QProcess and capturing output

    Thank you for the code, however I need to capture the output in real-time. The output appears on the screen in real time, and this is the only executable I am having problems with, so I know the concept of what I am trying to do works.

    Does QProcess wait for a certain character, like a new line escape character, before it acknowledges there is content to be read?

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
  •  
Qt is a trademark of The Qt Company.