I need to execute command line commands and tools that accept ut8 as input or generate an ut8 output. So i use cmd an it works, but when i try this from php with exec it doesn't work. To make it simple i tried simple output redirection.
When i write direct in command prompt:
chcp 65001 > nul && echo цчшщюя-öüäß>utf8.txt
The uft8.txt is created an the content is correct.
цчшщюя-öüäß
When i use the exec function from php:
$cmd = "chcp 65001 > nul && echo цчшщюя-öüäß>utf8.txt";
exec($cmd,$output,$return);
var_dump($cmd,$output,$return);
the content in the utf8.txt is messed up:
¥Å¥Î¥^¥%¥Z¥?-ÇôǬÇÏÇY
I am using Win7,64bit with (Console) Codepage 850.
What should i do to fix that?
Additional Infos: I am trying to overcome some issues with reading and writing of utf8 filenames on windows. PHP file functions fail: glob, scandir, file_exists can't handle utf8 filenames correctly. File are invisible, skipped, names are changed ... Therefore i want to avoid php file functions and i am looking for some php extern filehandling.
Since i couldn't find an easy, fast and reliable internal php solution, i am ending with using that i know it's work. Cmd-Batch-File. I make a small function that generate a cmd batch file in runtime. Its just prepends the the chcp (change the codepage) command in order to switch to unicode. And parse the output.
Usage: just like php exec():
OR