Jump to content

[Solved] How to write special characters to SciTE Editor? - (Moved)


Recommended Posts

$String = "áéőúűüóö"

ConsoleWrite($String)

My initial problem is SciTE unable to recognize the ű and ü and ő characters if I try to make a variable.

Here is an other exaple:

#include-once

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Language=1038
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <Array.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPIConv.au3>
#Include <WinAPI.au3>
#include <WinAPIConv.au3>

;--------END OF INCLUDES---------------------------------

        Local Const $SF_ANSI = 1
        Local Const $SF_UTF16_LE = 2
        Local Const $SF_UTF16_BE = 3
        Local Const $SF_UTF8 = 4
$sCommand = "powershell.exe  Get-ChildItem"

Local $iPid = Run($sCommand, @DesktopDir, @SW_SHOW, $STDOUT_CHILD)
ProcessWaitClose($iPid)
Local $sOutput = StdoutRead($iPid)

ConsoleWrite(@CRLF)
ConsoleWrite($sOutput)
ConsoleWrite(_WinAPI_WideCharToMultiByte($sOutput,2))
ConsoleWrite(_WinAPI_MultiByteToWideChar($sOutput,2))
ConsoleWrite(BinaryToString(StringToBinary($sOutput, $SF_ANSI), $SF_UTF8))
ConsoleWrite(StringToBinary($sOutput, $SF_UTF8))
$aLang = StringRegExp($sOutput, "(*UCP)(\p{Latin}+(?:\s+\p{Latin}+)*)", 1)
ConsoleWrite($aLang)

In this script, I use Get-ChildItem to list the files and directories to the console, but if I the direcoty or file contains ű or ő  or ü or ó etc. then it write out some strange characters.

I have read some topic in this forum about this issue, and I have already tried some of the funtions (see above in the script). 

As you can see I changed the language Directive #AutoIt3Wrapper_Res_Language=1038 to hungarian, which contains these characters.

Do you have any idea, how can I set to SciTE to recognize these charachters or how can I read properly from Powershell Console with these accents?

 

Edited by DannyJ
Link to comment
Share on other sites

  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
4 minutes ago, DannyJ said:

 SciTE

Guess you mean AutoIt3? 
Is this a CodePage(Ansi) versus UTF8 (Unicode) issue? Check your File/Encoding setting for the scriptfile. 

Jos

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

10 minutes ago, Jos said:

Guess you mean AutoIt3? 
Is this a CodePage(Ansi) versus UTF8 (Unicode) issue? Check your File/Encoding setting for the scriptfile. 

Jos

 

Thank you for your answer @Jos!

Yes I mean AutoIt3.

This is a CodePage issue as well.

I have already chechked the encoding and it set to UTF 8. (File/Encoding)

Link to comment
Share on other sites

  • Developers

Try this _ConsoleWrite() UDF  in stead of ConsoleWrite() to see if that fixes it for you as it is a known fact that the characters don't display properly:

Func _ConsoleWrite($s)
    ConsoleWrite(BinaryToString(StringToBinary($s, 4), 1))
EndFunc   ;==>_ConsoleWrite

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

14 minutes ago, Jos said:

Try this _ConsoleWrite() UDF  in stead of ConsoleWrite() to see if that fixes it for you as it is a known fact that the characters don't display properly:

Func _ConsoleWrite($s)
    ConsoleWrite(BinaryToString(StringToBinary($s, 4), 1))
EndFunc   ;==>_ConsoleWrite

Jos

Thanks @Jos, I have tried, but unfortunately _ConsoleWrite won't work :(.

If I write out with _ConsoleWrite function.          

The áé characters represented like:  ‚
The úű  represented like: Åű 
The őö  represented like: €¹â€                                           

Edited by DannyJ
Link to comment
Share on other sites

  • Developers
30 minutes ago, DannyJ said:

unfortunately _ConsoleWrite won't work :(.

It does for me. This simple script:

Func _ConsoleWrite($s)
    ConsoleWrite(BinaryToString(StringToBinary($s, 4), 1))
EndFunc   ;==>_ConsoleWrite

$test = "áé úű őö "
ConsoleWrite($test & @CRLF)
_ConsoleWrite($test & @CRLF)

Output:image.png.af1dce410acc1e583703b40e5e5904a3.png

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

13 minutes ago, Nine said:

Ya, consoleWrite is not the best tool to display unicode strings.  Use MsgBox or GUI Label instead.

Thank you very much @Nine

Here is my new code snippet:

#include-once

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Language=1038
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <Array.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPIConv.au3>
#Include <WinAPI.au3>
#include <WinAPIConv.au3>

;--------END OF INCLUDES---------------------------------

        Local Const $SF_ANSI = 1
        Local Const $SF_UTF16_LE = 2
        Local Const $SF_UTF16_BE = 3
        Local Const $SF_UTF8 = 4
$sCommand = "powershell.exe  Get-ChildItem"

Local $iPid = Run($sCommand, @DesktopDir, @SW_SHOW, $STDOUT_CHILD)
ProcessWaitClose($iPid)
Local $sOutput = StdoutRead($iPid)


MsgBox(0,"a", (_WinAPI_WideCharToMultiByte($sOutput,2 )))
MsgBox(0,"a", (_WinAPI_WideCharToMultiByte($sOutput,65000 )))
MsgBox(0,"a", (_WinAPI_WideCharToMultiByte($sOutput,65001 )))

Unfortunately none of them works :(

Do you have any other idea?

Link to comment
Share on other sites

  • Developers

Please post a script containing the offending characters so we can test with that as your example script obviously doesn't give the same result for us. ;) 

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Link to comment
Share on other sites

1 hour ago, DannyJ said:

Here is my new code snippet:

#include <AutoItConstants.au3>
Test()
Func Test()
    Local $sPath = @TempDir & "\GetChildItemTest"
    DirCreate($sPath)
    Local $sFileName = "Test " & Chr(250) & ".txt" ; some characters you'd like to test out
    ConsoleWrite(@CRLF & '>' & $sFileName & '<' & @CRLF)
    FileWriteLine($sPath & "\" & $sFileName, "Test")

    Local $sCommand = "powershell.exe Get-ChildItem -Path " & $sPath
    Local $iPid = Run($sCommand, @DesktopDir, @SW_SHOW, $STDOUT_CHILD)
    ProcessWaitClose($iPid)
    Local $sOutput = StdoutRead($iPid)
    ConsoleWrite($sOutput)
;~  DirRemove($sPath, 1)
EndFunc

...better snippet ;)

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

Link to comment
Share on other sites

9 minutes ago, Nine said:

_WinAPI_OemToChar ($sStream). 

#include <AutoItConstants.au3>
#include <WinAPIConv.au3>
Test()
Func Test()
    Local $sPath = @TempDir & "\GetChildItemTest"
    DirCreate($sPath)
    Local $sFileName = "Test " & Chr(250) & ".txt" ; some characters you'd like to test out
    ConsoleWrite(@CRLF & '>' & $sFileName & '<' & @CRLF)
    FileWriteLine($sPath & "\" & $sFileName, "Test")

    Local $sCommand = "powershell.exe Get-ChildItem -Path " & $sPath
    Local $iPid = Run($sCommand, @DesktopDir, @SW_SHOW, $STDOUT_CHILD)
    ProcessWaitClose($iPid)
    Local $sOutput = StdoutRead($iPid)
    ConsoleWrite(_WinAPI_OemToChar($sOutput)) ; @nine's solution
;~  DirRemove($sPath, 1)
EndFunc

 

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

Link to comment
Share on other sites

@Jos Thank you very much your help.

@Nine and @argumentum than you for your help, your solution with _WinAPI_OemToChar works perfectly.

 

Do you have any idea why I get this error: AutoIt3.exe ended.rc:-1073741819?

If I use powershell.exe Get-ChildItem | Format-List

 

Here is a my code: 

; Script Start - Add your code below here
#include <AutoItConstants.au3>
#include <WinAPIConv.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion

Test()

Func Test()

    ;Local $sCommand = "powershell.exe Get-ChildItem"
     Local $sCommand = "powershell.exe Get-ChildItem | Format-List "
    Local $iPid = Run($sCommand, @DesktopDir, @SW_SHOW, $STDOUT_CHILD)
    ProcessWaitClose($iPid)
    Local $sOutput = StdoutRead($iPid)
   ; ConsoleWrite(_WinAPI_OemToChar($sOutput)) ; @nine's solution
   ConsoleWrite($sOutput) 
  _WinAPI_OemToChar($sOutput) ; I get this error if I use | Format-List pipe
EndFunc

I would be very grateful If you could check my code and run with Get-ChildItem | Format-List, I have no idea why I get the above mentioned error.

Ps.: Unfortunately I need Format-List to make array from the command, and I use another commands as well.

Link to comment
Share on other sites

29 minutes ago, DannyJ said:

I have tried your idea,

Is not an idea. Know your pipes !?

29 minutes ago, DannyJ said:

unfortunately the console breaks the lines if ...

hmmm, that sucks. But you have a 120 char. wide line limit and that sucks too.  I was using | Format-Table -Property *

I don't have the output you show in the pic., so, could not replicate. No replication = no troubleshooting = no solution  Got it.

Edited by argumentum
solved

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

Link to comment
Share on other sites

...
    Local $a = StringSplit($sOutput, @CRLF & @CRLF, 1)
    For $n = 1 To UBound($a) -1
        ;; oops!!! ;; ConsoleWrite(_WinAPI_OemToChar($sOutput & @CRLF)) ; ..guess I'm still sleepy   =)
        If $a[$n] Then ConsoleWrite(_WinAPI_OemToChar($a[$n] & @CRLF & @CRLF))
    Next
...

:)

Edited by argumentum
oops

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

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

×
×
  • Create New...