rudi Posted January 13, 2020 Share Posted January 13, 2020 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: Open Notepad Enter this line into Notepad including the nice chars ä ö ü Ä Ö Ü ß Save it as a Text file, e.g. C:\temp\ASCII.TXT Open a CMD box 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 õ ÷ ³ ─ Í ▄ ▀ The opposite direction: Type in the CMD box: echo äöü ÄÖÜ ß > C:\temp\ASCII-CMD.txt 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 More sharing options...
Nine Posted January 13, 2020 Share Posted January 13, 2020 (edited) Look at those conversion functions : _WinAPI_OemToChar () + _WinAPI_CharToOem Works for me as I am using french KB... Edited January 13, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rudi Posted January 13, 2020 Author Share Posted January 13, 2020 Thanks for your reply. Could you provide a samle line, please? e.g. to put the properly ASCII spelling for "André" to a DOS txt file? TIA. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Zedna Posted January 13, 2020 Share Posted January 13, 2020 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 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Nine Posted January 13, 2020 Share Posted January 13, 2020 One way, using your ASCII-CMD.txt : #include <WinAPIConv.au3> $PID = Run (@ComSpec & " /c type ASCII-CMD.txt","",@SW_HIDE, $STDERR_MERGED) ProcessWaitClose ($PID) $str = _WinAPI_OemToChar(StdoutRead ($PID)) FileWriteLine ("Test.txt",$str) ConsoleWrite ($str & @CRLF) ShellExecute ("Test.txt") “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rudi Posted May 12, 2020 Author Share Posted May 12, 2020 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? expandcollapse popup#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 More sharing options...
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