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. Using bash with QProcess

Using bash with QProcess

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 10.3k Views
  • 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    Does anyone used QProcess to run bash?
    How can i exit the bash process?
    I tries bashProcess->write("exit\n\r") but it does'nt seems to work

    1 Reply Last reply
    0
    • S Offline
      S Offline
      saidiahd
      wrote on last edited by
      #2

      hi aabc ,
      I found this in the QProcess Class Reference :
      @
      The finished() signal provides the exit code and exit status of the process as arguments, and you can also call exitCode() to obtain the exit code of the last process that finished, and exitStatus() to obtain its exit status. If an error occurs at any point in time, QProcess will emit the error() signal. You can also call error() to find the type of error that occurred last, and state() to find the current process state.@

      "Learn from yesterday, live for today, hope for tomorrow." - Albert Einstein -

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on last edited by
        #3

        I explain it again
        My code is:
        @
        QProcess* process = new QProcess();
        process->start("bash");
        process->waitForStarted();
        process->write("route > /home/abc/aaa.txt\n\r");
        process->write("exit\n\r");
        process->waitForFinished();
        @

        For some reason - the process does not end after the "process->write("exit\n\r");" and the last line does not get called ?
        Any ideas?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

          Try removing the '\r' at the end of your lines, only '\n' is needed on linux/unix.

          And with that particular code, you could avoid using an intermediate file, by getting the output directly from QProcess:
          @QProcess* process = new QProcess();
          process->start("route");
          process->waitForFinished();
          QString output = process->readAll();@

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aabc
            wrote on last edited by
            #5

            Thanks!!!

            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