Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to resolve and understand how / why it works or not

how to resolve and understand how / why it works or not

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabaselinuxdebugginghelp
7 Posts 1 Posters 0 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Please understand that I am asking here and it is NOT a Qt question. My task is to start a new process - the parameters are "application" and its parameters. The basic process builds a "Database" and I am not so sure about "bin/sh" - I guess it "runs" a shell... It works and there is no need to get into why at this point. The "problem" is - the "process" is running and I need to interact with it. I can use "write" but I have no idea when and where and how. In the enclosed snippet the "info\n" is "send" to the file ( shell?) before it is finished... I do understand that Qt process can "wait for finished " and I can also get a SIGNAL when the file is actually done building. What I do not get - if the process is actually /physically building / writing a file - what does "wait for finished " waiting for ? Again - I am not asking how to code Qt , I am asking how to code so I can "write" the additional stuff in right time.

     std::string Database  = BT\_DATABASE\_TEST;
                std::string Command   = "bluetoothctl ";
                std::string command = Command + std::string(" | tee ") + Database  + std::string(" | tee /tmp/temp");
                QP->start("/bin/sh", QStringList() << "-c" << command.c\_str());
    
                qDebug()<< "TEST QProcess CONTINUE DEBUG point  @line " << QString::number(\_\_LINE\_\_);
                QP->waitForFinished();
                QP->write("info\\n");   writes too soon 
                qDebug() << QP->readAllStandardError();
                qDebug() << QP->readAllStandardOutput();
    
    L 1 Reply Last reply
    0
    • L Lost User

      Please understand that I am asking here and it is NOT a Qt question. My task is to start a new process - the parameters are "application" and its parameters. The basic process builds a "Database" and I am not so sure about "bin/sh" - I guess it "runs" a shell... It works and there is no need to get into why at this point. The "problem" is - the "process" is running and I need to interact with it. I can use "write" but I have no idea when and where and how. In the enclosed snippet the "info\n" is "send" to the file ( shell?) before it is finished... I do understand that Qt process can "wait for finished " and I can also get a SIGNAL when the file is actually done building. What I do not get - if the process is actually /physically building / writing a file - what does "wait for finished " waiting for ? Again - I am not asking how to code Qt , I am asking how to code so I can "write" the additional stuff in right time.

       std::string Database  = BT\_DATABASE\_TEST;
                  std::string Command   = "bluetoothctl ";
                  std::string command = Command + std::string(" | tee ") + Database  + std::string(" | tee /tmp/temp");
                  QP->start("/bin/sh", QStringList() << "-c" << command.c\_str());
      
                  qDebug()<< "TEST QProcess CONTINUE DEBUG point  @line " << QString::number(\_\_LINE\_\_);
                  QP->waitForFinished();
                  QP->write("info\\n");   writes too soon 
                  qDebug() << QP->readAllStandardError();
                  qDebug() << QP->readAllStandardOutput();
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I am assuming that your QP pointer is a reference to an object of QProcess Class | Qt Core 6.3.2[^]. As stated in the documentation the start method assumes the device mode as ReadWrite, which if it follows the normal rules, suggests you can write to and read from the started process. But writing will only work if the started process is waiting for input on its stdin stream. As far as I can see your started process is a simple shell pipeline to write some data to stdout and a couple of files. So it is not likely to be waiting for input from an external source.

      L 1 Reply Last reply
      0
      • L Lost User

        I am assuming that your QP pointer is a reference to an object of QProcess Class | Qt Core 6.3.2[^]. As stated in the documentation the start method assumes the device mode as ReadWrite, which if it follows the normal rules, suggests you can write to and read from the started process. But writing will only work if the started process is waiting for input on its stdin stream. As far as I can see your started process is a simple shell pipeline to write some data to stdout and a couple of files. So it is not likely to be waiting for input from an external source.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        After more research - I have two distinct usage of the "command" (QProcess) - one writes to the file and terminates and the other one is "interactive" - writes to the file and expects input. As of now I can "monitor" the first one two ways - in code - wait for finished or using "finished" SIGNAL. Right now my SIGNAL is "readyWrite" which ( the name ) does not make much sense - BUT it works with non - interactive command. I am going to take a closer look at QProcess SIGNALs - at least make more sense with non interactive command.As of now I just start the QProcess , and I am not directly ( using SIGNALs) verifying it is actually running / started. After I clean that up I'll take a look at interactive part. Not sure where to start.

        L 1 Reply Last reply
        0
        • L Lost User

          After more research - I have two distinct usage of the "command" (QProcess) - one writes to the file and terminates and the other one is "interactive" - writes to the file and expects input. As of now I can "monitor" the first one two ways - in code - wait for finished or using "finished" SIGNAL. Right now my SIGNAL is "readyWrite" which ( the name ) does not make much sense - BUT it works with non - interactive command. I am going to take a closer look at QProcess SIGNALs - at least make more sense with non interactive command.As of now I just start the QProcess , and I am not directly ( using SIGNALs) verifying it is actually running / started. After I clean that up I'll take a look at interactive part. Not sure where to start.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Member 14968771 wrote:

          Not sure where to start.

          The logical place is a tutorial on QProcess. You can only communicate with an independent process in this way, when the input and output streams are connected. The default option to the start method sets QIODeviceBase::OpenMode mode = ReadWrite. Does that mean that you can write to the process or not? Only a QT expert can advise on the answer.

          L 1 Reply Last reply
          0
          • L Lost User

            Member 14968771 wrote:

            Not sure where to start.

            The logical place is a tutorial on QProcess. You can only communicate with an independent process in this way, when the input and output streams are connected. The default option to the start method sets QIODeviceBase::OpenMode mode = ReadWrite. Does that mean that you can write to the process or not? Only a QT expert can advise on the answer.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I have verified that I can "write" to QProcess - the question remains when. Until now the command I have been testing with - which is why I am reluctant to post in QT forum - has been one of the challenges. There is no definite pattern when the command is "single shot" or interactive - depends on how it has been used before.

            L 1 Reply Last reply
            0
            • L Lost User

              I have verified that I can "write" to QProcess - the question remains when. Until now the command I have been testing with - which is why I am reluctant to post in QT forum - has been one of the challenges. There is no definite pattern when the command is "single shot" or interactive - depends on how it has been used before.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Member 14968771 wrote:

              I have verified that I can "write" to QProcess

              I am not sure what you mean, the write method is from the QProcess. There is a question on SO at https://stackoverflow.com/questions/45336371/qt-qprocess-how-to-write-to-standard-in[^] which may make some sense. But TBH it is still not clear exactly what you are trying to achieve.

              L 1 Reply Last reply
              0
              • L Lost User

                Member 14968771 wrote:

                I have verified that I can "write" to QProcess

                I am not sure what you mean, the write method is from the QProcess. There is a question on SO at https://stackoverflow.com/questions/45336371/qt-qprocess-how-to-write-to-standard-in[^] which may make some sense. But TBH it is still not clear exactly what you are trying to achieve.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I am making progress - one of the issues was I was getting multiple "readyRead" SIGNAls. Not sure why... Now I am getting only one per "start(...) " QProcess and my process stays open.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups