ofSystem / Curl string replacement error

Hey,

I am sending a CURL command using ofSystem and it works great when the string is submitted as a fully hard coded string.

    string cmd4 = "curl -X POST \
            -H \"Content-Type: application/json\" \
            -H \"application-id:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\" \
            -H \"secret-key:XXXXXXXX-XXXX-XXXXXX-XXXXXXXXXXX\" \
            -d \'{\"address\":\"email@email.com\"}\' \
            -v https://api.backendless.com/v1/data/email";
   ofSystem(cmd4);

When I use ofStringReplace to sub out part of the string for dynamic information I get

ofStringReplace(cmd4, "email@email.com", ofToString(userGroup[i].getEmail()));

sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file

Any idea what would have changed in the format of the string after using ofStringReplace?

An added note.

I am printing cmd4 to check if it has become malformed. Interestingly when I print the original hard coded one it copies and pastes into textEdit normally.

When I copy and paste the command after the replacement it highlights and seems to copy but will only paste up to the @ symbol in the email address…

If you do

std::cout << cmd4 << std::endl

can you paste / execute the final command in a terminal successfully? Basically it looks like ofSystem / bash is missing some ’ or ` or ’ …

No, as mentioned above it only pastes up to the @ symbol. Where if I do the same thing with the hardcoded string it works fine. Is it possible that there are invisible EOF symbols inserted into the string?

Ah, sorry I missed that. Three thoughts – 1) What file encoding are you using? Can you edit them as UTF-8? If you are using a special encoding, string replacements may act funny. 2) If you rearrange your string all into one line (no multi-line \ chars 3) The single quotes on your -d flag may be acting funny … could you try

-d \"{\"address\":\"email@email.com\"}\" \

or

--data-ascii \"{\"address\":\"email@email.com\"}\" \

Thanks for the help bakercp. I took a deeper look into the encoding etc with no avail. A small clue emerged from looking at the number of characters in the string. It looks like I was recording the “shift” key into the string when I would go to insert the @ symbol. All fixed. Small mistake, big headache. Thanks for the help