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. [SOLVED]Shell error output from QProcess
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Shell error output from QProcess

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 10.1k 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.
  • B Offline
    B Offline
    beefmusta
    wrote on last edited by
    #1

    How do you get the error message given by the shell if the command given to QProcess's start() method was invalid? E.g. on Linux, the shell returns a message "X: command not found". From what I can tell, the finished signal is not emitted in this case so you can't check that way. Also, calling readAllStandardOutput() and readAllStandardError() after waiting for the process to finish return empty if the command was invalid. How do you check for this case?
    Thanks

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      If you are on windows??

      In your pro file add:
      CONFIG += console

      And you start your program using the dos prompt from the Qt installation via Start...

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beefmusta
        wrote on last edited by
        #3

        My apologies, apparently I wasn't clear.
        I have a Qt project compiling and running O.K., the problem is it contains code to launch an external program using a QProcess object. The program string passed to the QProcess object's start() method is loaded dynamically and can be changed by the user. If the user has mistyped the string, or the command they have entered is invalid, I would like to give the user feedback by displaying the message normally returned by the shell (i.e. if you were to enter the command manually into the shell). Does that make sense?
        Thanks
        P.S. No I'm on Ubuntu

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          But you do not use the shell, so where should the error come from?

          You are using the system API for process start, which would be on Windows CreateProcess, whatever it is on Linux. This is different to the shell.

          Did you try to use the method "QProcess::errer":http://doc.qt.nokia.com/4.7/qprocess.html#error to get error information?

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

            I have a similar application. I use :

            @process->setProcessChannelMode(QProcess::MergedChannels);@

            [ interleaves the standard output and standard error of the running process. then reading standard output reads everything. Have a look at enum QProcess::ProcessChannelMode for other options.]

            @connect SIGNAL( readyReadStandardOutput() )@

            to a slot and print the output of readAllStandardOutput() in the slot.

            I am able to catch both error and normal output from the console program.

            But if the program name is misspelled, then enum ProcessError from function error() might help you.

            [EDIT: code formatting, Volker]

            1 Reply Last reply
            0
            • R Offline
              R Offline
              redkite
              wrote on last edited by
              #6

              Like Gerolf said, you are not using a shell, but the QProcess API. It's the error handler of your shell that is printing "X: command not found".

              With QProcess, you can achieve the same goal by reading ProcessError :

              @...
              connect(process, SIGNAL(error(QProcess::ProcessError)),
              this, SLOT(slotProcessError(QProcess::ProcessError)));
              ...

              void YourClass::slotProcessError(QProcess::ProcessError error)
              {
              ...
              switch (error) {
              case QProcess::FailedToStart :
              errorPTE->appendPlainText(trUtf8("> The process failed to start. Either the invoked
              program is missing, or you may have insufficient
              permissions to invoke the program."));
              break;
              ...
              }@

              1 Reply Last reply
              0
              • B Offline
                B Offline
                beefmusta
                wrote on last edited by
                #7

                Thanks for the clarification about the shell etc. I connected a slot to the QProcess::error() signal and it's working great.

                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