0

I'm trying to send a string as a shell argument via system() in php.

Everything works fine until I send a string with special characters like this one "Œ" in particular. So, when I send this string "ŒDucks" the shell just recieves "Ducks"

I've tried escaping it adding "/", "\", simple quotes but it doesnt matter, I get the same result

This is my code:

system('/usr/bin/perl /var/prof/info.pl'.' '.EscapeShellArg("ŒDucks") > /dev/null &');

Thanks for your time :)

Origineil
  • 3,108
  • 2
  • 12
  • 17
Mollo
  • 723
  • 3
  • 7
  • 24
  • 1
    What happens if you set `setlocale(LC_CTYPE, "en_US.UTF-8");` (or any utf-8 locale you have handy) before it? – Wrikken Oct 21 '13 at 19:33
  • Uhmm, interesting I just did it and I got this character "Å" instead "Œ" – Mollo Oct 21 '13 at 19:39
  • Hm, what _is_ the character set in you PHP application? – Wrikken Oct 21 '13 at 19:43
  • **utf8_spanish_ci** Guessing that is the same as the Data Base where I'm extracting the string – Mollo Oct 21 '13 at 19:46
  • And what _is_ the character set your Perl thing expects? `Å.. something` usually means it interprets _valid_ utf-8 (so it now survives the transport) as iso-8859-1* or similar (so it doesn't survive interpretation at the receiving end). (Also: be very sure about your database connection: do you set it _explicitly_ to utf-8? For `mysql`, a `SET NAMES utf8;` would do it). – Wrikken Oct 21 '13 at 19:58
  • Good question, how can I check what character set uses my PERL. I just started using it =S – Mollo Oct 21 '13 at 20:02
  • Hm, that's out of my comfort zone, [but it seems to have been asked on SO before](http://stackoverflow.com/questions/2037467/how-can-i-treat-command-line-arguments-as-utf-8-in-perl) – Wrikken Oct 21 '13 at 20:03
  • Ok, thanks for your help, I'll read that forum and try to figure it out – Mollo Oct 21 '13 at 20:09

1 Answers1

1

Try: setlocale(LC_CTYPE, "en_US.UTF-8"); or whatever locale that weirdness :) is from.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • I just did it and I got this character "Å" instead "Œ" Looks like I need to find the right locale – Mollo Oct 21 '13 at 19:40
  • Yes, apologies, I am one of those English only people and have had rare instances when I have to deal with anything other than that. – AbraCadaver Oct 21 '13 at 19:47