Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]Shell error output from QProcess

    General and Desktop
    5
    7
    9393
    Loading More Posts
    • 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
      beefmusta last edited by

      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 Reply Quote 0
      • E
        Eddy last edited by

        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 Reply Quote 0
        • B
          beefmusta last edited by

          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 Reply Quote 0
          • G
            giesbert last edited by

            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 Reply Quote 0
            • R
              rammi last edited by

              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 Reply Quote 0
              • R
                redkite last edited by

                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 Reply Quote 0
                • B
                  beefmusta last edited by

                  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 Reply Quote 0
                  • First post
                    Last post