Qt Forum

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

    Call for Presentations - Qt World Summit

    QProcess with find -exec

    General and Desktop
    2
    4
    2145
    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.
    • I
      iforce2d last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • I
          iforce2d last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post