Darien Posted July 1, 2017 Posted July 1, 2017 (edited) Hello, My Windows is in Portuguese. When I run a DOS command and get a character not found in the English language, it appears incorrectly. For example: $pid = Run ( @ComSpec & " /c netsh interface ipv4 show config" , "" , @SW_HIDE , $STDERR_CHILD + $STDOUT_CHILD ) $resultado = "" $erro = "" While 1 $resultado = $resultado & StdoutRead ( $pid ) $erro = $erro & StderrRead ( $pid ) If @error Then msgbox (0 , "" , $resultado ) WEnd The msgbox command displays the message: But the DOS command "netsh interface ipv4 show config" displays the result below: In the 1st line, for example, is displayed "Configura‡Æo da interface "ConexÆo local"" instead of "Configuração da interface "Conexão local"". Is there a way around this? Edited July 1, 2017 by Darien
jchd Posted July 2, 2017 Posted July 2, 2017 Try this: FileWrite("ÃãÇçÑñÕõ.tmp", "Hello World!") Local $pid = Run(@ComSpec & " /c dir ÃãÇçÑñÕõ.tmp", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $resultado = "" Do $resultado &= StdoutRead($pid) Until @error FileDelete("ÃãÇçÑñÕõ.tmp") MsgBox(0, "", _OemToStr($resultado)) Func _OemToStr($sOEM, $iCodepage = Default) If $iCodepage = Default Then $iCodepage = Int(RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage", "OEMCP")) Local $tText = DllStructCreate("byte[" & StringLen($sOEM) & "]") DllStructSetData($tText, 1, $sOEM) Local $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodepage, "dword", 0, "struct*", $tText, "int", StringLen($sOEM), _ "ptr", 0, "int", 0) Local $tWstr = DllStructCreate("wchar[" & $aResult[0] & "]") $aResult = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "uint", $iCodepage, "dword", 0, "struct*", $tText, "int", StringLen($sOEM), _ "struct*", $tWstr, "int", $aResult[0]) Return DllStructGetData($tWstr, 1) EndFunc ;==>_OemToStr This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Darien Posted August 8, 2025 Author Posted August 8, 2025 Hello, Starting with the 24H2 update, the function no longer works. Making the registry changes below makes it work again, but it has a side effect: AutoIt does not correctly read INI files that contain characters in Portuguese, using the IniRead command. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Nls\CodePage] "ACP"="65001" "OEMCP"="65001" "MACCP"="65001"
ioa747 Posted August 8, 2025 Posted August 8, 2025 (edited) when you open the ini file in notepad, what does it say in the bottom right? UTF-8 or ANSI? if it says ANSI, save it as UTF-8, and try reading it again with AutoIt Edited August 8, 2025 by ioa747 I know that I know nothing
Darien Posted August 9, 2025 Author Posted August 9, 2025 It is in ANSI format, but I don't want to have to change each file. I would like a simpler solution, such as changing a registry key or changing the _OemToStr function.
ioa747 Posted August 9, 2025 Posted August 9, 2025 (edited) go to 'Administrative language settings' and look under 'Current language for non-Unicode programs' if it says Portuguese. If it says Portuguese , and even then it doesn't read them correctly, then... I don't know any other solution. except #include <File.au3> #include <Array.au3> Local $aFiles = AllToUTF8(@ScriptDir, "*.ini", 1) Func AllToUTF8($dir, $sMask = "*", $iRecur = $FLTAR_NORECUR) If StringRight($dir, 1) <> "\" Then $dir &= "\" $aList = _FileListToArrayRec($dir, $sMask, 1, $iRecur, $FLTAR_NOSORT, $FLTAR_FULLPATH) If Not IsArray($aList) Then MsgBox($MB_SYSTEMMODAL, "Ooops!", "No .ini files found") Return SetError(1, 0, 0) Else For $i = 1 To $aList[0] Local $sTxt = FileRead($aList[$i]) Local $sNewName, $iN = "" Do $sNewName = StringTrimRight($aList[$i], 4) & ".old" & $iN If FileExists($sNewName) Then $iN += 1 Until Not FileExists($sNewName) FileMove($aList[$i], $sNewName) FileWrite($aList[$i], $sTxt) Next MsgBox($MB_SYSTEMMODAL, "Job Complete!", "All " & $aList[0] & " .ini files converted to UTF-8") EndIf EndFunc ;==>AllToUTF8 Edit: Just keep in mind that with the flag 1 in AllToUTF8(@ScriptDir, "*.ini", 1), it will do the conversion, in all .ini in all subfolders Edited August 9, 2025 by ioa747 I know that I know nothing
argumentum Posted August 9, 2025 Posted August 9, 2025 (edited) Am installing his version and language to see what would work 🤯 Edited August 9, 2025 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
argumentum Posted August 9, 2025 Posted August 9, 2025 2 hours ago, Darien said: It is in ANSI format, but I don't want to have to change each file. Zip the file so that I can download it in my Portuguese Win11 and see what you see. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
argumentum Posted August 9, 2025 Posted August 9, 2025 (edited) Local $pid = Run(@ComSpec & " /c netsh interface ipv4 show config", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $resultado = "" Do $resultado &= StdoutRead($pid) Until @error MsgBox(0, "", BinaryToString(StringToBinary($resultado, 1), 4)) Exit this worked as expected _OemToStr($sOEM, $iCodepage = 65001) ; also worked just fine. Edited August 9, 2025 by argumentum more Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
Darien Posted August 12, 2025 Author Posted August 12, 2025 Both "BinaryToString(StringToBinary($resultado, 1), 4)" and "_OemToStr($sOEM, $iCodepage = 65001)" work with the "netsh" command, but they mess up the characters in the "ipconfig /all" command.
argumentum Posted August 19, 2025 Posted August 19, 2025 On 8/12/2025 at 1:11 PM, Darien said: but they mess up the characters in the "ipconfig /all" command. I had good luck with 850 ( Brazil ), that was the return of the default OEMCP. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
Darien Posted August 19, 2025 Author Posted August 19, 2025 The problem is that I don't want to keep creating If statements for each command, because I don't know which other commands will need one or the other option. I wanted a general solution.
argumentum Posted August 19, 2025 Posted August 19, 2025 ...is what M$ did. Not an AutoIt thing. If they don't abide by their own rules, what can we do ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
argumentum Posted August 19, 2025 Posted August 19, 2025 Func _OemToStr_BruteForce($sOEM) Local $iCodepage = Int(RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage", "OEMCP")) Local $iExt, $sRet, $aCodepages = [$iCodepage, 850, 65001, 0] ; Some common codepages For $n = 0 To UBound($aCodepages) - 1 $sRet = _OemToStr($sOEM, $aCodepages[$n]) If StringInStr($sRet, "ç") Then ExitLoop Next Return SetError(0, $aCodepages[$n], $sRet) EndFunc ;==>_OemToStr_BruteForce Try that ?. In this example the "ç" has to be found because "Configuração" appears in both commands. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
Solution argumentum Posted August 19, 2025 Solution Posted August 19, 2025 Func _OemToStr_BruteForce($sOEM) Local $iCodepage = Int(RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Nls\Codepage", "OEMCP")) Local $iExt, $sRet, $aCodepages = [$iCodepage, 850, 65001, 0] ; Some common codepages For $n = 0 To UBound($aCodepages) - 1 $sRet = _OemToStr($sOEM, $aCodepages[$n]) $iExt = $aCodepages[$n] If CharInStr_NotIt($sRet) Then ContinueLoop ExitLoop Next Return SetError(0, $iExt, $sRet) EndFunc ;==>_OemToStr_BruteForce Func CharInStr_NotIt($sRet) Local $aArray = StringToASCIIArray($sRet) For $n = 0 To UBound($aArray) - 1 If $aArray[$n] > 8000 Then Return 1 Next EndFunc ;==>CharInStr_NotIt This should do nicely for your language Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
Darien Posted August 26, 2025 Author Posted August 26, 2025 Thank you very much! It worked perfectly. argumentum 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now