Jump to content
DannyJ

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

Recommended Posts

I managed to solve this problem:

............
Local $aArray = StringRegExp($sOutput, "(?|filterd commands)\h*:\h*(.*)", 3)
_ArrayDisplay($aArray)


$CommandLength = 14
; convert 1d array into 2d array
Local $aFinal[UBound($aArray) / $CommandLength][$CommandLength]
For $i = 0 To UBound($aFinal) - 1
    $aFinal[$i][0] = _WinAPI_OemToChar($aArray[$i * $CommandLength])
    $aFinal[$i][1] = _WinAPI_OemToChar($aArray[$i * $CommandLength + 1])
    $aFinal[$i][2] = _WinAPI_OemToChar($aArray[$i * $CommandLength + 2])
    $aFinal[$i][3] = _WinAPI_OemToChar($aArray[$i * $CommandLength + 3])
    $aFinal[$i][4] = _WinAPI_OemToChar($aArray[$i * $CommandLength + 4])
    $aFinal[$i][5] = _WinAPI_OemToChar($aArray[$i * $CommandLength + 5])


..............

When I fill the final array I use _WinAPI_OemToChar function, so it changes line by line.

Thank you very much your help: @Nine and @argumentum and @Jos :)

I mark this topic closed.

Share this post


Link to post
Share on other sites
2 hours ago, DannyJ said:

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

I tested both on Win7 and Win10.  Did not get this error. It means that AutoIt crashed.

Do you have full Scite and the latest version ?  What AutoIt  version do you have  ?

Have you tried to MsgBox the output instead of ConsoleWrite ?

I know you have solved your issue but there is something fishy with your config...

Share this post


Link to post
Share on other sites
21 minutes ago, Nine said:

I tested both on Win7 and Win10.  Did not get this error.

He was choking, really killing it. Was just too much at once. Now chopped is manageable. He could get whatever he wanted in a different way, but noooo, he's a powershell  guy, so, ... that's that @Nine :) 
[Solved] :thumbsup:

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

I tested both on Win7 and Win10.  Did not get this error. It means that AutoIt crashed.

Do you have full Scite and the latest version ?  What AutoIt  version do you have  ?

Have you tried to MsgBox the output instead of ConsoleWrite ?

I know you have solved your issue but there is something fishy with your config...

Thanks @Nine 

I use Windows Server 2019 Version 1809.

I use Scite 32-bit Version 4.4.6 

I use AutoIt 3.3.14.5 version.

Yes I have tried MsgBox.

The problem could be the config (I use that my company  provided me)

Do you have any recommendations to change my config?

Thanks for your help in advance.

Share this post


Link to post
Share on other sites

IDK, you seem to have the latest versions.  One thing is sure, AutoIt should not crash like that.  How big is your $sOutput (StringLen) ?  Unless, we can find a replicable snippet of the code, it is going to be very hard to propose a solution.

Share this post


Link to post
Share on other sites
Posted (edited)

I think I have found the problem.  Try this :

#include <Constants.au3>
#include <WinAPIConv.au3>

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

Test()

Func Test()
  Local $sCommand = "powershell.exe Get-ChildItem | Format-List "
  Local $iPid = Run($sCommand, @WindowsDir, @SW_SHOW, $STDOUT_CHILD)
  ProcessWaitClose($iPid)
  Local $sOutput = StdoutRead($iPid)
  ConsoleWrite(_WinAPI_OemToCharEx($sOutput))
EndFunc

Func _WinAPI_OemToCharEx($sStr)
  Local $aRet = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', $sStr, 'str', '')
  If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
  Return $aRet[2]
EndFunc   ;==>_WinAPI_OemToChar

 

Edited by Nine

Share this post


Link to post
Share on other sites

Thank you very much @Nine

I have tested, it is good, have a nice day :)

Quote

  How big is your $sOutput (StringLen) ?

Not really big my input.

Share this post


Link to post
Share on other sites
Test()
Func Test()
    Local $sCommand = @ComSpec & " /c powershell.exe ""Get-ChildItem -Path " & @TempDir & "  | Format-List -Property *"" "
    Local $iPid = Run($sCommand, "", @SW_SHOW, $STDOUT_CHILD)
    ProcessWaitClose($iPid)
    Local $sOutput = StdoutRead($iPid)
;~  ConsoleWrite(__WinAPI_OemToCharA($sOutput)) ; !>14:32:58 AutoIt3.exe ended.rc:-1073741819
;~  ConsoleWrite(__WinAPI_OemToChar($sOutput)) ;  !>14:34:21 AutoIt3.exe ended.rc:-1073740940
    ConsoleWrite($sOutput) ;                      +>14:34:44 AutoIt3.exe ended.rc:0
EndFunc

Func __WinAPI_OemToCharA($sStr)
  Local $aRet = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', $sStr, 'str', '')
  If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
  Return $aRet[2]
EndFunc   ;==>_WinAPI_OemToCharA

Func __WinAPI_OemToChar($sStr)
    Local $aRet = DllCall('user32.dll', 'bool', 'OemToChar', 'str', $sStr, 'str', '')
    If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
    Return $aRet[2]
EndFunc   ;==>_WinAPI_OemToChar

it does not solve the issue, with a StringLen() of 156364

Share this post


Link to post
Share on other sites
Posted (edited)
Test()

Func Test()
  Local $sCommand = "powershell.exe Get-ChildItem | Format-List -Property *"
  Local $iPid = Run($sCommand, @WindowsDir, @SW_SHOW, $STDOUT_CHILD)
  ProcessWaitClose($iPid)
  Local $sOutput = StdoutRead($iPid)
  MsgBox ($MB_SYSTEMMODAL, "", StringLen($sOutput))
  ConsoleWrite(_WinAPI_OemToCharEx($sOutput))
EndFunc

Func _WinAPI_OemToCharEx($sStr)
  Local $aRet = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', $sStr, 'str', $sStr)
  If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
  Return $aRet[2]
EndFunc   ;==>_WinAPI_OemToChar

That seems to resolve the problem.

msdn says :

Quote

If the OemToChar function is being used as an ANSI function, the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter.

@argumentum  I see you were quite brisk to denounce the ticket...

Edited by Nine

Share this post


Link to post
Share on other sites
3 hours ago, Nine said:

I see you were quite brisk to denounce the ticket...

I don't mean to be harsh in any way. I do point that even tho it needs the correction you present, it does not take care the problem, of a large enough string, to be too much.
Chunking it would be a solution. I would not like to have a fix that is to believe to be it, to then find that it was not bullet proof. That's all.
I come in peace. A bit sleepy this morning, but in peace. I have you in high regard and would not like for you to find offence in my doings.

Love you man, and pardon my presentation. Did not mean to ... any aggravation, in any sense.

Share this post


Link to post
Share on other sites

On-place OEM to Char (that is OEM [some legacy DOS codepage] to ANSI [some non-DOS single-byte codepage]) won't convert the upper part of any DOS codepage correctly. All of them contain characters (e.g. borders ╚╔╩╦ or blocks ░▒▓█▄▀ and several more) that are not in ANSI.

Only OEM to multibyte (UTF8) then multibyte to UCS2 (subset of UTF16) can convert everything verbatim at the cost of twice as much string bytelength.

(No offence to anyone intended here)


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)

Share this post


Link to post
Share on other sites
Posted (edited)
ConsoleWrite(_WinAPI_WideCharToMultiByte($sOutput, 2)) ;  +>20:24:52 AutoIt3.exe ended.rc:0

now that returned what I expected, but is "2" = "The current system Macintosh code page".
Why Macintosh ?. Macintosh like in Apple ?.

PS: "â ã ä" is not returned as such under any format (OemToChar or WideCharToMultiByte)

Edited by argumentum
more questions

Share this post


Link to post
Share on other sites
Test()
Func Test()
    FileWriteLine(@TempDir & "\Test__ " & Chr(0xE2) & " " & Chr(0xE3) & " " & Chr(0xE4) & ".txt", Chr(0xE2) & " " & Chr(0xE3) & " " & Chr(0xE4))
    Local $sCommand = @ComSpec & " /c powershell.exe ""Get-ChildItem -Path " & @TempDir & "  | Format-List -Property *"" "
    Local $iPid = Run($sCommand, "", @SW_SHOW, $STDOUT_CHILD)
    ProcessWaitClose($iPid)
    Local $sOutput = StdoutRead($iPid)
    ConsoleWrite(__WinAPI_OemToCharA($sOutput))
;~  ConsoleWrite(__WinAPI_OemToChar($sOutput))
EndFunc   ;==>Test

Func __WinAPI_OemToChar($sStr) ; these are turned into helper functions.
    Local $sRet = __WinAPI_OemToChar_Internal_1($sStr, "OemToChar")
    Return SetError(@error, @extended, $sRet)
EndFunc   ;==>__WinAPI_OemToChar

Func __WinAPI_OemToCharA($sStr) ; these are turned into helper functions.
    Local $sRet = __WinAPI_OemToChar_Internal_1($sStr, "OemToCharA")
    Return SetError(@error, @extended, $sRet)
EndFunc   ;==>__WinAPI_OemToCharA

Func __WinAPI_OemToChar_Internal_1($sStr, $OemToCharType = "OemToChar", $sRet = "")
    Do ;                      $sRet = "" is to save me the local declaration, but may not be kosher.
        $sRet &= __WinAPI_OemToChar_Internal_2(StringLeft($sStr, 1024 * 64), $OemToCharType)
        If @error Then Return SetError(@error, @extended, $sRet)
        $sStr = StringTrimLeft($sStr, 1024 * 64)
    Until Not StringLen($sStr)
    Return $sRet
EndFunc   ;==>__WinAPI_OemToChar_Internal_1

Func __WinAPI_OemToChar_Internal_2($sStr, $OemToCharType = "OemToChar")
    Local $aRet = DllCall('user32.dll', 'bool', $OemToCharType, 'str', $sStr, 'str', '')
    If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
    Return $aRet[2]
EndFunc   ;==>__WinAPI_OemToChar_Internal_2

...the above does the chunking I meant, and brings flexibility for OemToChar, OemToCharA and OemToCharW.
( not that I know any better of what's what, but it does the chunking )

Share this post


Link to post
Share on other sites

hi,

AutoIt allocate only for "str" parameter only 65536 bytes So

the solution is 

Func _WinAPI_OemToChar_($sStr)
    Local $aCall, $sRetStr = "", $nLen = StringLen($sStr), $iLen = 1

    While $iLen <= $nLen
        $aCall = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', StringMid($sStr, $iLen, 65536), 'str', '')
        If @error Or Not $aCall[0] Then Return SetError(@error + 10, @extended, '')
        $sRetStr &= $aCall[2]
        $iLen += 65536
    WEnd

    Return $sRetStr
EndFunc   ;==>_WinAPI_OemToChar

 

I will fix it

Not sure more _WinAPI_* functions need to do the same ...

Cheers

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lynn Shaw
      Anyone know why _ArraySearch is not finding an entry with a single quote in it?  
      Here is an example:
      #include <array.au3>
      Dim $array[3][2]
      $array[0][0] = "Testing is****fun"
      $array[1][0] = "Don't mess with me kid"
      $array[2][0] = "blah'blah"
      _ArrayDisplay($array)
      $index = _ArraySearch($array, "blah'blah", 0, 0, 0, 0, 1, 1)
      MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$index' & @CRLF & @CRLF & 'Return:' & @CRLF & $index) ;### Debug MSGBOX
×
×
  • Create New...