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. Issue in QProcess with quotes and spaces
Forum Updated to NodeBB v4.3 + New Features

Issue in QProcess with quotes and spaces

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.9k 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.
  • S Offline
    S Offline
    Shutta
    wrote on last edited by
    #1

    Hi everyone,
    I'm trying to execute an external command from my QT program, the problem is that the command has several arguments and quotes. In bash only, the command runs fine but I've tried to execute it with QProcess and it has been an impossible task for me. I've has tried with single quotes, triple quotes and many more ways, but none works.
    The command in bash is:
    tshark -n -r example.pcap -Y "rtp.ssrc==0x00002e3d" -T fields -e rtp.payload
    Anybody can give me some idea to do that with QProcess please?
    Thanks in advance

    JonBJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      Try this:

      QStringList args = {
        "-n",
        "-r",
        "example.pcap",
        "-Y", 
        "\"rtp.ssrc==0x00002e3d\"",
        "-T",
        "fields",
        "-e",
        "rtp.payload"
      };
      
      QProcess proc("tshark", args);
      

      (Z(:^

      1 Reply Last reply
      3
      • S Shutta

        Hi everyone,
        I'm trying to execute an external command from my QT program, the problem is that the command has several arguments and quotes. In bash only, the command runs fine but I've tried to execute it with QProcess and it has been an impossible task for me. I've has tried with single quotes, triple quotes and many more ways, but none works.
        The command in bash is:
        tshark -n -r example.pcap -Y "rtp.ssrc==0x00002e3d" -T fields -e rtp.payload
        Anybody can give me some idea to do that with QProcess please?
        Thanks in advance

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @Shutta
        As @sierdzio has written, it's often nicer/clearer/safer to pass your arguments separately for QProcess to sort out quoting. (Though that may be a pain, depending on how your code is arranged to construct the command.)

        (However, I don't see an overload of QProcess() constructor matching his suggestion, I think he meant QProcess proc; proc.start("tshark", args);.)

        However, just OOI, in whatever you say you tried what would not have worked with:

        proc.start("tshark -n -r example.pcap -Y \"rtp.ssrc==0x00002e3d\" -T fields -e rtp.payload")

        ?

        And for the record, in this particular case there is nothing in your rtp.ssrc==0x00002e3d argument which requires quoting, so you could simply omit the complexities of quoting and go:

        proc.start("tshark -n -r example.pcap -Y rtp.ssrc==0x00002e3d -T fields -e rtp.payload")

        though you may have good reason to be quoting that argument in case in contains other characters than it does.

        S 1 Reply Last reply
        3
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @JNBarchan said in Issue in QProcess with quotes and spaces:

          (However, I don't see an overload of QProcess() constructor matching his suggestion, I think he meant QProcess proc; proc.start("tshark", args);.)

          Yeah you are right, sorry, I have not checked the docs before sending ;-)

          (Z(:^

          1 Reply Last reply
          1
          • JonBJ JonB

            @Shutta
            As @sierdzio has written, it's often nicer/clearer/safer to pass your arguments separately for QProcess to sort out quoting. (Though that may be a pain, depending on how your code is arranged to construct the command.)

            (However, I don't see an overload of QProcess() constructor matching his suggestion, I think he meant QProcess proc; proc.start("tshark", args);.)

            However, just OOI, in whatever you say you tried what would not have worked with:

            proc.start("tshark -n -r example.pcap -Y \"rtp.ssrc==0x00002e3d\" -T fields -e rtp.payload")

            ?

            And for the record, in this particular case there is nothing in your rtp.ssrc==0x00002e3d argument which requires quoting, so you could simply omit the complexities of quoting and go:

            proc.start("tshark -n -r example.pcap -Y rtp.ssrc==0x00002e3d -T fields -e rtp.payload")

            though you may have good reason to be quoting that argument in case in contains other characters than it does.

            S Offline
            S Offline
            Shutta
            wrote on last edited by
            #5

            @JNBarchan thanks very much for your answer.
            The way proc.start("tshark -n -r example.pcap -Y "rtp.ssrc==0x00002e3d" -T fields -e rtp.payload") didn't work for me, but I don't know why it do works copying the whole command within a QString variable. Also works without quotes, but I hasn't proved because in original formula appeared as rtp.ssrc == 0x00002e3d (with spaces).
            Now is working fine, thanks

            JonBJ 1 Reply Last reply
            0
            • S Shutta

              @JNBarchan thanks very much for your answer.
              The way proc.start("tshark -n -r example.pcap -Y "rtp.ssrc==0x00002e3d" -T fields -e rtp.payload") didn't work for me, but I don't know why it do works copying the whole command within a QString variable. Also works without quotes, but I hasn't proved because in original formula appeared as rtp.ssrc == 0x00002e3d (with spaces).
              Now is working fine, thanks

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #6

              @Shutta
              proc.start("tshark -n -r example.pcap -Y "rtp.ssrc==0x00002e3d" -T fields -e rtp.payload") would not work, I never suggested that. Please use copy & paste for examples from suggestions here.

              If you now say you want spaces in one of the arguments (it always helps if you post the exact question as you want it in the first place), you would need:
              proc.start("tshark -n -r example.pcap -Y \"rtp.ssrc == 0x00002e3d\" -T fields -e rtp.payload")
              Or you might prefer to do as @sierdzio suggested, with separate arguments in a list, to avoid dealing with quoting. However, note that what he wrote is not quite right, you would then not want embedded quotes, his rtp.ssrc argument should read "rtp.ssrc == 0x00002e3d".

              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