Problem using stdout in QProcess



  • I am a new in QT. need to catch the output from the process which I started.
    What I am doing wrong?

    Thank you.

    @ QString program = "echo";
    QStringList arguments;
    arguments << "test >/dev/stdout";

     QProcess *myProcess = new QProcess(this);
    
     myProcess->start(program, arguments);
     myProcess->setReadChannel( QProcess::StandardOutput );
     char buff[1024];
    
      qint64 len = myProcess->readLine( buff, qint64(1024));
      int len = myProcess->readLine( buff, qint64(1024));
      printf(" buffer %s %d \n", buff, int(len));@
    

    get nothing as result



  • You don't give your process time to actually start doing something. Use the QProcess::readyRead() signal, and connect it to a slot where you do the actual reading.



  • Or just waitForFinished() after start().
    Tricky part might be getting those arguments right



  • [quote author="Tomma" date="1300440105"]Or just waitForFinished() after start().
    Tricky part might be getting those arguments right[/quote]
    I recommend against using the waitFor* methods in Qt if you can avoid them at all, especially if you are building GUI applications.



  • [quote author="Andre" date="1300440589"]I recommend against using the waitFor* methods in Qt if you can avoid them at all, especially if you are building GUI applications.
    [/quote]

    Let's say it that way:

    If you are building command line apps with have to wait, waitFor* makes sense.
    If you build Gui, use signals.



  • I agree with Gerolf. This way must work for you.



  • Be aware that you can not use shell input/output redirection (how should it work - there is no shell involved!). So this is wrong (in the sense of it does not do what you intended):

    @
    arguments << "test >/dev/stdout";
    @



  • All, thank you very much. I am out of the office now, will test this soon. Sure it works.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.