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. Getting Console output from a script.
Forum Updated to NodeBB v4.3 + New Features

Getting Console output from a script.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.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.
  • M Offline
    M Offline
    Mschudder
    wrote on last edited by
    #1

    Hello

    I am struggling getting output from the console.

    @ QProcess OProcess;
    QString Command = "grunt > /tmp/lolx.txt";

    QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
    OProcess.start(Command);
    
    QString ab =        OProcess.readAll();
    

    ui->txtBrowserTerminal->append(ab);

    QString StdOutx     =   OProcess.readAllStandardOutput();  //Reads standard output
    QString StdErrorx    =   OProcess.readAllStandardError();   //Reads standard error@
    

    When I run the command "ls" or something like that everything is working perfectly.

    But when running the "Grunt" command I do not seem to get any output :/ can anyone explain me why ?

    I am sure I am in the right folder, and when I run the command from a terminal it works.

    Grunt = gruntjs.com/getting-started

    Thanks
    kind regards

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      welcome to devnet

      From your code snippet it looks like you read before the process has been finished. Check out "waitForFinished":http://qt-project.org/doc/qt-5/qprocess.html#waitForFinished

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mschudder
        wrote on last edited by
        #3

        Hello,

        Thanks, well I have tried that aswell
        @ QProcess OProcess;
        QString Command = "grunt > /tmp/lolx.txt";

        QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
        OProcess.start(Command);
        OProcess.waitForFinished(-1);
        
        QString StdOut      =   OProcess.readAllStandardOutput();  //Reads standard output
        QString StdError    =   OProcess.readAllStandardError();   //Reads standard error
         QString a =        OProcess.readAll();
        
        ui->txtBrowserTerminal->append(a);
        ui->txtBrowserTerminal->append(StdOut);
        ui->txtBrowserTerminal->append(StdError);@
        

        But nothing comes out, when I run the command ,after I run this process , in my terminal I see the result in my terminal but nothing in my txtBrowserTerminal.

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

          Hi,

          You are redirecting the output of grunt in a file, so (unless I'm mistaken) you should not have anything on stdout only on stderr.

          You should try to run grunt without any redirection to catch its output with QProcess.

          Hope it helps

          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
          • M Offline
            M Offline
            Mschudder
            wrote on last edited by
            #5

            Hello,

            Well I tried that aswell :/ was just trying to see if the file gets created but that's not the case aswell.

            So I am guessing he doesn't call it .. or can't call it.

            Can I debug this ?

            Thanks

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

              Where is grunt located ?

              Check what QProcess::error() returns

              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
              • M Offline
                M Offline
                Mschudder
                wrote on last edited by
                #7

                It returns no such file or directory.

                But then when I try:
                @ QProcess OProcess;
                QString Command = "/usr/local/bin/grunt";

                QDir::setCurrent(ui->plainTxtBrowserFolder->toPlainText() + "/");
                OProcess.start(Command);
                OProcess.waitForFinished(-1);
                
                QString error = OProcess.errorString();
                ui->txtBrowserTerminal->append(error);
                

                @

                It returns " unknown error" and "env: node: No such file or directory"

                So now he doesn't find "node".

                I think the problem is that this QProcess doesn't get my PATH variables ? or doesn't has access to it ?

                Thanks already man !

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

                  You can set the environment of QProcess using setProcessEnvironment

                  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