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] QProcess

[Solved] QProcess

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.9k 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.
  • S Offline
    S Offline
    Seba84
    wrote on last edited by
    #2

    I would do the following:

    don't call bash as the program you want to execute but directly "ls" with absolute path and arguments ">" & "output"

    use the QProcess::waitForFinished() function to start the file reading

    Here the code with the two modifications:
    @QProcess process;
    process.start("/usr/bin/ls", QStringList() << ">" << "Output.txt");
    if(process.waitForFinished())
    readfromProcess();@

    Does this solves your problem?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      toa1
      wrote on last edited by
      #3

      No it doesn't. In fact it doesn't seem to run the program ls at all, at least there is no Output.txt located on the file system. And it does not enter the readfromProcess() function.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toa1
        wrote on last edited by
        #4

        I have tried a lot of different approaches, but to get any output at all I had to
        [code]
        process.start("bash");
        process.write("bash commands");
        [/code]

        1 Reply Last reply
        0
        • T Offline
          T Offline
          toa1
          wrote on last edited by
          #5

          Well, I did get ls to run, and it did finally link to the output. One thing is ls is located on my file system from /bin. The arguments don't seem to work with the QStringList though.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Seba84
            wrote on last edited by
            #6

            Can you post your solution code?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Seba84
              wrote on last edited by
              #7

              I have just tested the next code and it does the job correctly:
              @
              process.setStandardOutputFile("output.txt");
              process.start("/bin/ls -lA");
              process.waitForFinished();
              @

              The command "ls < output.txt" doesn't work (I don't know why), that is why I call the function setStandardOutputFile().

              1 Reply Last reply
              0
              • T Offline
                T Offline
                toa1
                wrote on last edited by
                #8

                Well, I don't actually have a working code for what I am trying to do yet. The problem with the < output.txt is the piping. < is a pipe and that is a separate process, so you need to create a second process to handle the piping... or more neatly as you did it. Once the ls program terminates, so does the thread or the process. That is also why starting bash and writing a pipe into it did work, because the process is running bash and doesn't terminate. So it can then it seems handle a piping within that thread or process. (at least that is what I have gathered, and filled in with my own imagination) I still have not gotten QStringList to work and I will most likely need it.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  toa1
                  wrote on last edited by
                  #9

                  I may just try concatenating a complex command and running bash. It will be messy and it may not work, but neither has the last 50 attempts.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Seba84
                    wrote on last edited by
                    #10

                    But, sorry I do not understand. The code I have posted above doesn't solve your problem? What do you need exactly?

                    By the way, this code with QStringList args also works:
                    @
                    process.setStandardOutputFile("output.txt");
                    process.start("/bin/ls", QStringList() << "-lA");
                    process.waitForFinished();
                    @

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      toa1
                      wrote on last edited by
                      #11

                      I see. I was looking at the arguments in the wrong framework I think. I am trying to add more commands or process'. I am trying to interface with namecoind daemon. So querying the namecoin database, and receiving Json objects. I do have the process working correctly now, thank you.

                      [code]
                      process.start("/usr/local/bin/namecoind", QStringList() << "name_show" << inputString);
                      [/code]

                      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