QProcess with find -exec
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.
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
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!!
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 :)