Jump to content

Recommended Posts

Posted (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:

 

msgbox.jpg

 

But the DOS command "netsh interface ipv4 show config" displays the result below:

 

DOS.jpg

 


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 by Darien
Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

  • 8 years later...
Posted

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"

Posted (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 by ioa747

I know that I know nothing

Posted

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.

Posted (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...

uuid-76da72e2-736e-ca4a-af75-3e960814bee


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 by ioa747

I know that I know nothing

Posted (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 by argumentum
more

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...