Jump to content

German Umlauts and CONSOLE Programs


rudi
 Share

Recommended Posts

Hi,

I have an issue with a console program, that Needs to receive ASCII text. As this is a German envirionment, these *LOVLEY* German Umlaut Chars are giving me Trouble.

 

How to see what I'm talking about:

 

  1. Open Notepad
  2. Enter this line into Notepad including the nice chars ä ö ü Ä Ö Ü ß
  3. Save it as a Text file, e.g. C:\temp\ASCII.TXT
  4. Open a CMD box
  5. there Show the Content of the file typing...
    type c:\temp\ascii.txt
C:\Users\admin>type c:\temp\ascii.txt
Enter this line into Notepad including the nice chars õ ÷ ³ ─ Í ▄ ▀
  1. The opposite direction:
    Type in the CMD box:
    echo äöü ÄÖÜ ß > C:\temp\ASCII-CMD.txt
  2. Open that file with Notepad
„” Ž™š á

 

I'm Aware of one approach to accomplish this Task: It's working when using WordPad.exe --> Using "save as" I can choose as file Format "Text document - MS-DOS-Format"

 

Any clue howto write a TXT string in "MS-DOS Format" from an Autoit Script?

It doesn't seem to make any difference, what's the code page set in the CMD box:

chcp --> active Codepage: 850

chcp 437 --> changes CP to 437

the Output is the same messed up thing as explained above.

 

The CLI Program I want to pass a string is "SENDXMS.EXE". It's using a GSM terminal to send Status SMS to Service stuff. Of course I could replace "ä"--> "ae" and so on, before passing the SMS txt string to that program. But it would be much better to just pass the "umlauts" correctly to this application.

 

Any suggestions appreciated, Rudi.

 

 

 

 

 

 

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Link to comment
Share on other sites

This is my old testing script for czech diacritic chars conversion DOS/ANSI:

#AutoIt3Wrapper_Change2CUI=y

ConsoleWrite(Ansi2Oem('Řádek 1') & @CRLF)
ConsoleWrite(Ansi2Oem('Řádek 2: ěščřžýáíé') & @CRLF)
ConsoleWrite(Ansi2Oem('Řádek 3'))

$text = ConsoleRead()
ConsoleWrite(Ansi2Oem(@CRLF & 'Zadaný text: ' & $text))

Func Ansi2Oem($text)
    $text = DllCall('user32.dll','Int','CharToOem','str',$text,'str','')
    Return $text[2]
EndFunc

Func Oem2Ansi($text)
 $text = DllCall('user32.dll','Int','OemToChar','str',$text,'str','')
 Return $text[2]
EndFunc

 

Link to comment
Share on other sites

  • 3 months later...

Thanks to both of you.

Zedna's method is working both directions perfectly.

 

With the _WinAPI_OemToChar the results are as expected. Not for the other direction, when I use _WinAPI_CharToOEM()

 

What do I miss?

#include <WinAPIConv.au3>


; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

$PID = Run (@ComSpec & " /c type c:\temp\ASCII-CMD.txt","",@SW_HIDE, $STDERR_MERGED)
ProcessWaitClose ($PID)
$DosTxt=StdoutRead ($PID)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $DosTxt = ' & $DosTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console


 $WinTxt=Oem2Ansi($DosTxt)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :  $WinTxt = ' &  $WinTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Back2ASCII=Ansi2Oem($WinTxt)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Back2ASCII = ' & $Back2ASCII & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; simply writing the converted STRING doesn't work
$fOut="C:\temp\Back2ASCII.TXT"
FileDelete($fOut)
FileWriteLine($fOut,$Back2ASCII)
FileWriteLine($fOut,"plain ""FileWriteLine""")
RunWait(@comspec & " /k type " & $fOut)



FileDelete($fOut)
; opening the file *BINARY* is doing the trick
$f=FileOpen($fOut,2+16) ; binary
FileWriteLine($f,$Back2ASCII)
FileWriteLine($f,"file opened binary for write")
FileClose($f)
RunWait(@comspec & " /k type " & $fOut)

;~ $text = ConsoleRead()
;~ ConsoleWrite(Ansi2Oem(@CRLF & 'Zadaný text: ' & $text))

Func Ansi2Oem($text)
    $text = DllCall('user32.dll','Int','CharToOem','str',$text,'str','')
    Return $text[2]
EndFunc

Func Oem2Ansi($text)
 $text = DllCall('user32.dll','Int','OemToChar','str',$text,'str','')
 Return $text[2]
EndFunc

ConsoleWrite("---------- END of approach from Zedna ------------" & @CRLF)
;~ ; in the CMD box drop the command "ECHO André äöü ÄÖÜ ß > c:\temp\ASCII-CMD.txt

$PID = Run (@ComSpec & " /c type c:\temp\ASCII-CMD.txt","",@SW_HIDE, $STDERR_MERGED)
ProcessWaitClose ($PID)
$DosTxt=StdoutRead ($PID)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $DosTxt = ' & $DosTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; Converting to appropriate STRING to be used within WINDOWS is working fine, thx!
$WinTxt= _WinAPI_OemToChar($DosTxt)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WinTxt = ' & $WinTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; Back to DOS TXT doesn't seem to work? (to send back input to a CMDLINE DOS Program
$Back2DosTXT=_WinAPI_CharToOem($WinTxt)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Back2DosTXT = ' & $Back2DosTXT & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$fOut="C:\Temp\WinApi-CharToOem.txt"
FileDelete($fOut)
FileWriteLine ($fOut,$Back2DosTXT)
FileWriteLine($fOut,"_WinAPI_CharToOEM, plain ""FileWriteLine""")
RunWait(@comspec & " /k type " & $fOut)


; ShellExecute ($fOut)
; notepad++ is showing, that an UTF-8 file is created.


FileDelete($fOut)
$f=FileOpen($fOut,2+16) ; binary
FileWriteLine($f,$Back2DosTXT)
FileWriteLine($fOut,"_WinAPI_CharToOEM, with FileOpen (16) - binary write.")
FileClose($f)
RunWait(@comspec & " /k type " & $fOut)

FileDelete($fOut)
$f=FileOpen($fOut,2+512) ; ANSI
FileWriteLine($f,$Back2DosTXT)
FileWriteLine($fOut,"_WinAPI_CharToOEM, with FileOpen (512) - ANSI write.")
FileClose($f)
RunWait(@comspec & " /k type " & $fOut)

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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