Forum Discussion

Henry1's avatar
Henry1
Contributor
2 years ago

UTF-8 encoding alternative for scripting needed

Hello community.

 

I'm struggeling with finding an alternative to the UTF-8 encoding method provided by dotNET due to the fact that dotNET requires a licensed desktop module which is not available on all machines.

 

To give you an example:

 

The next line of code works well with dotNET.

 

   utf8DecodedText := dotNET.System_Text.Encoding.UTF8.GetString(myArray).OleValue;

 

I tried to work around the license problem with OLE.

 

   UTF8Encoding := Sys.OleObject('System.Text.UTF8Encoding');

   utf8DecodedText := UTF8Encoding.GetString(myArray);

 

Unfortunatly just an error dialog pops up saying "wrong parameter".

I've already tried to explore the GetString method with the OLE/COM object viewer but unfortunatly the methods are not public in mscorlib.tlb

 

I've also googled on this topic without success.

 

Does anyone have an alternative suggestion for UTF-8 encoding?

 

 

 

    • Henry1's avatar
      Henry1
      Contributor

      I came across this suggestion already yesterday.

       

      Unfortunatly this works correct in powershell itself. But if I call the powershell via WshShell.Exec within my script the UTF-8 encoding is gone because it seams that WshShell only can handle ascii in stdout.

       

      Try this as a simple example:

      oExec := WshShell.Exec('powershell -command echo ßäöü');
      oExec.StdIn.Close;

      strOutput := oExec.StdOut.ReadAll;

      Log.Message(strOutput);

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    PowerShell

    Actual encoding will convert to bytes

    or using dotNet

     

    • Henry1's avatar
      Henry1
      Contributor

      Thank you for confirming that unicode characters works well in PowerShell itself. It does not work by calling the PowerShell via WshShell within TC due to the fact that WshShell only can handle ascii in stdout.

       

      Back to my initial question: I already have an array and I want to pass it somehow to an alternative function that returns me a utf-8 decoded string.

       

      As mentioned above it works well with dotNET with this line of code:

      utf8DecodedText := dotNET.System_Text.Encoding.UTF8.GetString(myArray).OleValue;

      Log.Message(utf8DecodedText);

       

      BTW. Log.Message can handle unicode characters.

       

       

       

       

       

       

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What if you use "cmd /u /c ...", to output internal commands to a pipe or file to be Unicode