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. how to pipe qprocess' stdout to father process as stdin
Qt 6.11 is out! See what's new in the release blog

how to pipe qprocess' stdout to father process as stdin

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 4 Posters 24.8k Views 2 Watching
  • 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.
  • JonBJ JonB

    @Isolde
    I do think if you can manage with that it will be a lot simpler than trying to do it from Qt.

    Now that I have understood your objective, I will say that there is nothing wrong about it as a desired facility in Qt. However, so far as I can see (and I have Googled a lot) Qt does not offer any means of redirecting a parent process's (not QProcess) own stdin/stdout/stderr from/to a piped child process, and that is actually a lacking feature in its otherwise comprehensive library.

    I Offline
    I Offline
    Isolde
    wrote on last edited by
    #28

    @JNBarchan I found a workaround.
    Now I using QProcess's startDetached() like

            QProcess* restart;
            restart = new QProcess;
            restart->startDetached("bash -c \"streamlink -O | my-qt-program \"");
            exit(0);
    

    It works well!

    JonBJ 1 Reply Last reply
    0
    • I Isolde

      @JNBarchan I found a workaround.
      Now I using QProcess's startDetached() like

              QProcess* restart;
              restart = new QProcess;
              restart->startDetached("bash -c \"streamlink -O | my-qt-program \"");
              exit(0);
      

      It works well!

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #29

      @Isolde
      Yes, you mean, you have written that as a second Qt application which does this to invoke your original Qt application, instead of a script file. Which is what we were suggesting :) [EDIT: Or, do you mean you actually do this from within your original "my-qt-program"?]

      jsulmJ I 2 Replies Last reply
      2
      • JonBJ JonB

        @Isolde
        Yes, you mean, you have written that as a second Qt application which does this to invoke your original Qt application, instead of a script file. Which is what we were suggesting :) [EDIT: Or, do you mean you actually do this from within your original "my-qt-program"?]

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #30

        @JNBarchan said in how to pipe qprocess' stdout to father process as stdin:

        Or, do you mean you actually do this from within your original "my-qt-program

        That would be an endless loop :-)

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        I JonBJ 2 Replies Last reply
        0
        • JonBJ JonB

          @Isolde
          Yes, you mean, you have written that as a second Qt application which does this to invoke your original Qt application, instead of a script file. Which is what we were suggesting :) [EDIT: Or, do you mean you actually do this from within your original "my-qt-program"?]

          I Offline
          I Offline
          Isolde
          wrote on last edited by
          #31

          @JNBarchan said in how to pipe qprocess' stdout to father process as stdin:

          is

          Not quite. I just add a simple if statement that determine whether to execute this restart code like

              if(QCoreApplication::arguments().at(1) != "bypass-parser")
              {
                  QProcess* restart;
                  restart = new QProcess;
                  restart->startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " + QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\"");
                  exit(0);
              }
          
          1 Reply Last reply
          0
          • jsulmJ jsulm

            @JNBarchan said in how to pipe qprocess' stdout to father process as stdin:

            Or, do you mean you actually do this from within your original "my-qt-program

            That would be an endless loop :-)

            I Offline
            I Offline
            Isolde
            wrote on last edited by
            #32

            @jsulm I'm sorry. They are not the whole codes, I post them completely in the last reply.

            jsulmJ 1 Reply Last reply
            0
            • I Isolde

              @jsulm I'm sorry. They are not the whole codes, I post them completely in the last reply.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #33

              @Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:

              if(QCoreApplication::arguments().at(1) != "bypass-parser")
              {
                  QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " +     QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\"");
                  QCoreApplication::exit(0);
              }

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              I 2 Replies Last reply
              3
              • jsulmJ jsulm

                @Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:

                if(QCoreApplication::arguments().at(1) != "bypass-parser")
                {
                    QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " +     QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\"");
                    QCoreApplication::exit(0);
                }
                I Offline
                I Offline
                Isolde
                wrote on last edited by
                #34

                @jsulm Got it. I'll amend it. Thank you very much.

                1 Reply Last reply
                1
                • jsulmJ jsulm

                  @JNBarchan said in how to pipe qprocess' stdout to father process as stdin:

                  Or, do you mean you actually do this from within your original "my-qt-program

                  That would be an endless loop :-)

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #35

                  @jsulm said in how to pipe qprocess' stdout to father process as stdin:

                  @JNBarchan said in how to pipe qprocess' stdout to father process as stdin:

                  Or, do you mean you actually do this from within your original "my-qt-program

                  That would be an endless loop :-)

                  That's why I asked, and he has posted to show how he detects....

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:

                    if(QCoreApplication::arguments().at(1) != "bypass-parser")
                    {
                        QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " +     QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\"");
                        QCoreApplication::exit(0);
                    }
                    I Offline
                    I Offline
                    Isolde
                    wrote on last edited by
                    #36

                    @jsulm said in how to pipe qprocess' stdout to father process as stdin:

                    @Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:

                    if(QCoreApplication::arguments().at(1) != "bypass-parser")
                    {
                        QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " +     QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\"");
                        QCoreApplication::exit(0);
                    }
                    

                    There is a strange problem, my program won't exit with QCoreApplication::exit(0);(but it could exit normally with exit(0)), I saw two windows with QCoreApplication::exit(0);. And the terminal output indicated that the old process had run into the GUI drawing step.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #37

                      So you want to control mpv from your application ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

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