Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem using stdout in QProcess

Problem using stdout in QProcess

Scheduled Pinned Locked Moved General and Desktop
8 Posts 6 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vkonstantinov
    wrote on 18 Mar 2011, 08:51 last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 18 Mar 2011, 09:15 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomma
        wrote on 18 Mar 2011, 09:21 last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 18 Mar 2011, 09:29 last edited by
          #4

          [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.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on 18 Mar 2011, 09:48 last edited by
            #5

            [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.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Darryl DSouza
              wrote on 18 Mar 2011, 10:01 last edited by
              #6

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

              Darryl D'Souza

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on 18 Mar 2011, 17:28 last edited by
                #7

                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";
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vkonstantinov
                  wrote on 19 Mar 2011, 03:04 last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  6/8

                  18 Mar 2011, 10:01

                  • Login

                  • Login or register to search.
                  6 out of 8
                  • First post
                    6/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved