system command with single quote characters in the string

Kenneth Brody kenbrody at spamcop.net
Wed Jun 19 17:11:11 PDT 2013


On 6/19/2013 6:44 PM, James Flanagan wrote:
> I am trying to send a unix command that requires " ' " (single quote
> characters) to encapsulate the data that is being added as metadata in a
> file. I have tried using the " \ " prior to each single quote character, and
> if I msgbox the uc variable from the code below, the resulting command
> appears perfect. however, when uc is actually run by the system command, the
> single quotes do not appear to be translated properly because I get a
> message on the screen that says" Error - File not Found - bedroom". That
> tells me that the single quotes are not being respected to keep "master
> bedroom" as a single string. Therefore, exiftool misinterprets bedroom as
> the filename due to the space character between master and bedroom.
>
> I am using FilePro 5.7 on FreeBSD 9.0 p3.
>
> I am hopeful that there is an easy solution to this.  thank you very much,
>
>
> ::fn="/tmp/test.jpg":
> ::va="master bedroom":
> ::uc="/usr/local/bin/exiftool -q -iptc^AObjectName=\'"{va{"\'"<fn:
> ::system noredraw uc:

I'm not on a *nix box at the moment, but IIRC the problem is that you need 
to use a triple-backslash-quote in order for the shell to see backslash-quote.

See, for example:

 
http://stackoverflow.com/questions/13689738/keeping-double-quotes-when-passing-string-to-popen-in-c

(Yes, it's an article about "popen" and not "system", but the same basic 
rules apply.)

I believe you need:

     uc="/usr/local/bin/exiftool -q -iptc:ObjectName=\\\'"{va{"\\\'"<fn

As I said, I'm not on a *nix box at the moment, so I can't test it, but it 
should be a simple test for you to try.

-- 
Kenneth Brody


More information about the Filepro-list mailing list