cmd.exe encoding (code page) lazarus / 34-Windows ---------------------------------------------------------------------- jcmontherock · 2022-01-31 10:12 Is somebody knows how to detect the code page or encoding of cmd.exe ? In my PC (W11/64) I found several versions of it. Only one is in the path by default: "c:\Windows\System32\cmd.exe" which has the CP1252 code page (Ansi- Latin-1). This one is not in the path: "c:\Windows\SysWOW64\cmd.exe" has 65001 code page (utf-8). Strange, no ? ---------------------------------------------------------------------- Jorg3000 · 2022-01-31 10:38 I suspect that if you call it with - ShellExecuteW() - CreateProcessW() using PWideChar/PWChar (UnicodeString/WideString) you shouldn't have to worry about the encoding. ---------------------------------------------------------------------- BobDog · 2022-01-31 10:55 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   program codepage;uses process; vars:ansistring;beginRunCommand('c:\windows\sys tem32\cmd.exe', ['/c', 'echo system32'], s);write(s);RunCommand('chcp.com', s);writeln(s); RunCommand('c:\Windows\SysWOW64\cmd.exe', ['/c', 'echo SysWOW64'], s);write(s);RunCommand('chcp.com', s);writeln(s); writeln('Press enter to end . . .');;readln;end.     (win 10 64 bits here) ---------------------------------------------------------------------- engkin · 2022-01-31 13:08 Maybe GetConsoleOutputCP? ---------------------------------------------------------------------- jcmontherock · 2022-01-31 14:53 I want to test the pipeline transfer example as shown in: https://forum.lazarus.freepascal.org/index.php/topic,58084.0.html with TProcessUTF8. ---------------------------------------------------------------------- PascalDragon · 2022-01-31 15:00 Quote from: jcmontherock on January 31, 2022, 11:12:21 amIs somebody knows how to detect the code page or encoding of cmd.exe ? What exactly do you mean with “encoding of cmd.exe”? A binary itself does not have an encoding. The encoding of the command line itself is controlled by various system settings (regional settings, startup scripts, registry, etc.). ---------------------------------------------------------------------- jcmontherock · 2022-01-31 15:06 In the console properties you'll find it: so the result of any instruction will be given with that code page. ---------------------------------------------------------------------- PascalDragon · 2022-01-31 15:31 Would you please check whether your registry contains any of the following keys: HKCU\Console\%SystemRoot%_System32_cmd.exeHKCU\Console\%SystemRoot%_Sy sWOW64_cmd.exe And in either of them the value CodePage? If not, what does your HCKU\Console contain as keys? And does it have a value CodePage? ---------------------------------------------------------------------- jcmontherock · 2022-01-31 15:45 In HKCU\Console\%SystemRoot%_System32_cmd.exe I have an entry "CodePage: 1252" and "CodePageFound: 1252". In HKCU\Console\%SystemRoot%_SysWOW64_cmd.exe I have no CodePage entry. In the others 3 entries, for PowerShell: No CodePage. ---------------------------------------------------------------------- Thaddy · 2022-01-31 17:31 chcp without parameters will reveal the CP. ---------------------------------------------------------------------- PascalDragon · 2022-02-01 08:05 Quote from: jcmontherock on January 31, 2022, 04:45:06 pmIn HKCU\Console\%SystemRoot%_System32_cmd.exe I have an entry "CodePage: 1252" and "CodePageFound: 1252". In HKCU\Console\%SystemRoot%_SysWOW64_cmd.exe I have no CodePage entry. In the others 3 entries, for PowerShell: No CodePage. Well, that explains the difference you see. Since the one in SysWOW64 has no CodePage key it will use either the one directly in HKCU\Console (if it exists) or the system default which probably is 65001. But to check it from within your application use GetConsoleOutputCP as mentioned by engkin. ---------------------------------------------------------------------- jcmontherock · 2022-02-01 09:35 I will try GetConsoleOutputCP. Thanks everybody... ---------------------------------------------------------------------- SymbolicFrank · 2022-02-01 09:39 You will also get a different result from a 32-bit and 64-bit application. ---------------------------------------------------------------------- marcov · 2022-02-01 10:06 Note that since Windows 10-1705 (1805?) there is also somewhere some setting to change default codepage to utf8. It is not default though. I highly doubt that the default is 65001. Rather the default ansi codepage for the US. ---------------------------------------------------------------------- BobDog · 2022-02-01 10:57 If it is of any help, this works for UK system. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function  wsystem(s:widestring):integer ; cdecl external 'msvcrt.dll' name '_wsystem';function  system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';beginwsystem('chcp');wsystem('chcp 65001'); writeln('Зарегистрируйтесь сейчас на Десятую Международную Конференцию по');writeln('Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.');writeln('Конференция соберет широкий круг экспертов по  вопросам глобального');writeln('Интернета и Unicode, локализации и интернационализации, воплощению и');writeln('применению Unicode в различных операционных системах и программных');writeln('приложениях, шрифтах, верстке и многоязычных компьютерных системах.');writeln('Press return to exit . . .');readln;end.  result here Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Active code page: 850Active code page: 65001Зарегистрируйтесь сейчас на Десятую Международную Конференцию поUnicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.Конференция соберет широкий круг экспертов по  вопросам глобальногоИнтернета и Unicode, локализации и интернационализации, воплощению иприменению Unicode в различных операционных системах и программныхприложениях, шрифтах, верстке и многоязычных компьютерных системах.Press return to exit . . . note wsystem or system will do this here. ---------------------------------------------------------------------- engkin · 2022-02-01 23:38 Quote from: jcmontherock on January 31, 2022, 03:53:41 pmI want to test the pipeline transfer example as shown in: https://forum.lazarus.freepascal.org/index.php/topic,58084.0.html with TProcessUTF8. On Win7 I could not get correct text from the pipeline using TProcessUTF8. On the other hand, using cmd /U worked with dir |MyApp Notice the parameter /U affects "internal commands" One thing I didn't try is changing the default setting for apps that do not support Unicode in the Control Panel. The same setting mentioned by Marco above. It needs a restart which I did not want to do.