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. QProcess with find -exec
Forum Updated to NodeBB v4.3 + New Features

QProcess with find -exec

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.5k 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.
  • I Offline
    I Offline
    iforce2d
    wrote on 30 Mar 2013, 06:21 last edited by
    #1

    I am using QProcess to call 'find', which works fine with most parameters and search options, until I try to use the -exec feature. For example, this command:

    find -exec pwd ;

    ...should print out the cwd n times, where n is the number of files 'find' found (not a practical example of course, but just to keep things simple). However, the result of this is: /usr/bin/find: missing argument to `-exec'

    I don't completely understand the need for the ; demarcation at the end (although I have been using it for years ! :) but perhaps this is causing some kind of unusual situation that QProcess cannot deal with?

    I realize that the pwd here is starting a whole new process, so maybe QProcess simply cannot do that? Just wondering if this is a lost cause, or whether I can do something about it.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Apr 2013, 07:30 last edited by
      #2

      Hi,

      the ; is used to tell find that the exec command ends there. The semicolon is also used by the shell to start multiple commands on the same line in the case you want them to run without checking the previous command result as opposed to && or ||. Thus the semicolon has to be escaped so find can see it and the shell does not use it.

      With QProcess, since you pass a string you get an invalid escape sequence, try the the same with \;

      Hope it helps

      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
      0
      • I Offline
        I Offline
        iforce2d
        wrote on 5 Apr 2013, 09:08 last edited by
        #3

        Your suggestion was not exactly right but it was very close. I found that removing the escape character completely works:

        find -exec pwd ;

        I guess this is because with QProcess there is only one command in the first place, so there is no need to handle multiple commands on the same line. Thanks!!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Apr 2013, 09:22 last edited by
          #4

          You're welcome !

          Don't forget to update the thread's title to solved so other forum users may know a solution has been found :)

          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
          0

          1/4

          30 Mar 2013, 06:21

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved