Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get QProcess output
Qt 6.12 LTS is out! See what's new in the release blog

Get QProcess output

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.4k Views 1 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.
  • MasterBLBM Offline
    MasterBLBM Offline
    MasterBLB
    wrote on last edited by
    #1

    Hello felow Qt programmers

    How can I get output of external application which was started in command line console via QProcess::startDetached("cmd", args, workingDir)?
    The problem is in case of error console is closed immediately, and I can't see what's wrong. Morever, the "/K" switch seems to not work:

    args << "/K" << "start" << "the app to be started in console";
    

    From what I've found in google I need inter process communication, but I failed to get any meaningful details how to redirect stdout and stderr into my Qt application.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • MasterBLBM MasterBLB

      Hello felow Qt programmers

      How can I get output of external application which was started in command line console via QProcess::startDetached("cmd", args, workingDir)?
      The problem is in case of error console is closed immediately, and I can't see what's wrong. Morever, the "/K" switch seems to not work:

      args << "/K" << "start" << "the app to be started in console";
      

      From what I've found in google I need inter process communication, but I failed to get any meaningful details how to redirect stdout and stderr into my Qt application.

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

      @MasterBLB Did you connect slots to https://doc.qt.io/qt-5/qprocess.html#readyReadStandardError and https://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput ?

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

      1 Reply Last reply
      4
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Apart from what @jsulm said you must not use startDetached if you want to read stdout/stderr from the process.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        4
        • MasterBLBM Offline
          MasterBLBM Offline
          MasterBLB
          wrote on last edited by
          #4

          startDetached() is a must as it turned out, otherwise the cmd with injected command won't work correctly.
          Reading standard error and output based on readiness signals worked, but not the way I need - the output is buffered and flushed each few seconds, while I need each byte of data available immediately, so I was forced to abandon that solution.

          1 Reply Last reply
          0
          • MasterBLBM MasterBLB

            Hello felow Qt programmers

            How can I get output of external application which was started in command line console via QProcess::startDetached("cmd", args, workingDir)?
            The problem is in case of error console is closed immediately, and I can't see what's wrong. Morever, the "/K" switch seems to not work:

            args << "/K" << "start" << "the app to be started in console";
            

            From what I've found in google I need inter process communication, but I failed to get any meaningful details how to redirect stdout and stderr into my Qt application.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @MasterBLB
            I don't understand what you are trying to achieve with cmd /K start ...? And if you're going to call start I don't see how you think any amount of stdout/stderr redirection will have the slightest effect (99% sure that with start there is no carry-over of std-streams), or for that matter why you then need startDetached().

            If you need IPC for this that is a quite separate matter....

            1 Reply Last reply
            2
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Why is "cmd /K start" needed at all?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2

              • Login

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