Qt Forum

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

    Qt Academy Launch in California!

    No content from readAll()

    General and Desktop
    3
    8
    1778
    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.
    • J
      jocala last edited by

      I'm trying to check existence of a file on an android device via the adb command. The attempt to grab the console output via command=readAll() returns empty every time.

      @
      QProcess *check_busybox2=new QProcess;
      check_busybox2->setProcessChannelMode(QProcess::MergedChannels);
      cstring = adb + " -s " + daddr+port + " shell ls /system/xbin/which";
      check_busybox2->start(cstring);
      check_busybox2->waitForFinished(-1);
      command=check_busybox2->readAll();
      delete check_busybox2;

             if (command.contains("No such file or directory"))
               QMessageBox::information( this,"","Busybox uninstalled " + command);
             else
              QMessageBox::critical( this,"","Busybox not uninstalled! " + command);
      

      @

      I can run the command from the console and get expected output, capture the output to a file, etc. Why is readAll() returning an empty string?

      1 Reply Last reply Reply Quote 0
      • C
        ChrisW67 last edited by

        Chances are that either:

        the command you are giving QProcess, cstring) is not correct; or

        the environment in which you "run the command from the console and get expected output" and the one that QProcess is working with are not the same.

        In either case, you should check QProcess::error() and QProcess::exitStatus() for clues.

        My money is on option 1: it looks like you are pasting the address and port number together without intervening whitepsace/punctuation. You should consider the other QProcess::start() overload.

        BTW: There seems to be no reason to allocate the QProcess object on the heap.

        1 Reply Last reply Reply Quote 0
        • J
          jocala last edited by

          You have a sharp eye, thanks:)

          BTW: There seems to be no reason to allocate the QProcess object on the heap.

          So, like this?

          @
          QProcess check_dir;
          check_dir.setProcessChannelMode(QProcess::MergedChannels);
          cstring = adb + " -s " + daddr + port + " shell ls /system/xbin/which";
          check_dir.start(cstring);
          check_dir.waitForFinished(-1);
          command=check_dir.readAll();
          @

          If I did it correctly above, why is this method better?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            AFAIK, when calling start and having arguments, you should use the same pattern as described "here":http://qt-project.org/doc/qt-5/qprocess.html#details
            Passing parameters can be tricky

            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 Reply Quote 0
            • C
              ChrisW67 last edited by

              [quote author="jocala" date="1404621560"]
              If I did it correctly above, why is this method better? [/quote]

              Allocation on the stack means you do not have worry about (i.e. cannot forget) freeing the memory you allocated.

              1 Reply Last reply Reply Quote 0
              • J
                jocala last edited by

                Allocation on the stack means you do not have worry about (i.e. cannot forget) freeing the memory you allocated.

                That would be the code below? (or are there other steps?)

                @
                delete processname;
                @

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Indeed, but in the present case, it's not useful to allocate QProcess on the heap to delete it right after since it won't survive the function.

                  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 Reply Quote 0
                  • J
                    jocala last edited by

                    Thanks for the feedback. Learn a little more every day :)

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post