Deutsche Umlaute

Forums Desktop Info Deutsche Umlaute

Tagged: 

Viewing 15 reply threads
  • Author
    Posts
    • #2299 Reply
      AvatarWolfgang

      Hallo,
      Wie kann ich bitte deutsche Umlaute wbspw. ö oder ü darstellenß

      Danke

      0
    • #2301 Reply
      GlennGlenn
      Keymaster

      Desktop Info will display German language correctly but you must save the desktopinfo.ini with UTF-8 encoding.

      • This reply was modified 4 months, 2 weeks ago by GlennGlenn.
      Attachments:
      0
    • #2342 Reply
      AvatarWolfgang

      Hallo Glenn,
      Vielen Dank, so einfach kann es doch sein.

      0
    • #2378 Reply
      AvatarBender

      Is it possible to display non-ASCII characters from PowerShell output with the CMD command in Desktop Info v2.1? I’ve tried it with the Write-Output and Write-Host functions and to set the $OutputEncoding variable to UTF8 in PowerShell first, but it seems that German umlauts aren’t displayed correctly in Desktop Info:

      CMD=active:1,wide:1,file:powershell.exe,parameters:Write-Host äöüß -NoNewline,display:Test1 %4
      CMD=active:1,wide:1,file:powershell.exe,parameters:Write-Output äöüß,display:Test2 %4
      CMD=active:1,wide:1,file:powershell.exe,parameters:$OutputEncoding = [System.Text.Encoding]::UTF8; Write-Host äöüß -NoNewline,display:Test3 %4
      CMD=active:1,wide:1,file:powershell.exe,parameters:$OutputEncoding = [System.Text.Encoding]::UTF8; Write-Output äöüß,display:Test4 %4

      screenshot

      0
      • #2380 Reply
        GlennGlenn
        Keymaster

        silly me didn’t make it wide string. I’ll raise a bug and get that fixed for the next release.

        1+
      • #2389 Reply
        GlennGlenn
        Keymaster

        I’ve been able to make the CMD item unicode aware. What I haven’t been able to figure out is how to encourage Powershell to output text in unicode.

        0
        • #2391 Reply
          AvatarBender

          Have you tried the commands I posted above? If I output into a text file, e.g. with “>” or with “Out-File”, it will be saved as UTF-8.

          By the way, I somehow can’t write a post in the “Useful Powershell Commands” thread, when I click on Submit it refreshes the page but nothing happens 🙁

          0
          • #2397 Reply
            GlennGlenn
            Keymaster

            Yes I’m using your example to test the Unicode code. Retrieving unicode back through the pipe is the key. I have it working with cmd.exe but not with powershell.exe.

            I think the issue with the other thread is that posts with attachments need to be approved. So I found all three of your attempts awaiting approval. The forum didn’t notify me 🙁

            0
        • #2394 Reply
          AvatarBender

          Seems like this forum blocks my post, but I’m not sure why. Perhaps a spam filter? Can you view filtered posts and unblock it somehow, because it might be useful for others?

          0
        • #2392 Reply
          AvatarBender

          As I apparently can answer here, this is what I meant to post, perhaps it is useful for others:

          If you use GitHub, you can query and display the number of new notifications from the GitHub API with PowerShell. For that you will first need a personal access token with the “notifications” permission for the account authentification via the command line (can be created in your GitHub account under Settings > Developer settings > Personal access token). I store it in a new environment variable named GITHUB_TOKEN, so that I don’t have to put it in my configuration file for Desktop Info. Then I use the following command to extract the number of new notifications (replace “username” with your GitHub username):
          CMD=active:1,interval:900,file:powershell.exe,parameters:Invoke-RestMethod -Headers @{Authorization = 'Basic {0}' -f [System.Convert]::ToBase64String([char[]]\"username:$Env:GITHUB_TOKEN\");} -Uri https://api.github.com/notifications | Select-Object -ExpandProperty Count | Write-Host -NoNewline,text:GitHub,display:%4 new notifications

          screenshot

          0
    • #2409 Reply
      GlennGlenn
      Keymaster

      I’ve been googling for days and I’m at a loss as to how to make Powershell write unicode to stdout. If anyone has working code then please post.

      0
    • #2467 Reply
      AvatarBender

      Hi Glenn,
      I wrote an answer some days ago, but apparently it was lost in the forums’ filter again, probably because it contained some links. However, I can call and display PowerShell comands with unicode output from a C/C++ program by using wide character strings and corresponding functions like _wsystem(). According to your previous post, you already tried this, right? If it still doesn’t work, could you reveal some more details about your implementation attempts?

      0
      • #2471 Reply
        GlennGlenn
        Keymaster

        You should test Powershell with DTI v2.2 and let me know if it returns Unicode.

        0
        • #2472 Reply
          AvatarBender

          I use v2.2 and Unicode does not work for me with the CMD command and PowerShell. Neither to display the stdout result directly via the “display:%4” option, nor to save it into a variable and then use that variable later with the CONTROL command (this is what I actually want to do).
          What does work however is, to save it into a text file with PowerShell first (Set-Content -Encoding UTF8 -Path tmp.txt), and then read from that text file with the FILE2TEXT command.

          0
          • #2473 Reply
            GlennGlenn
            Keymaster

            Ok. well until i read to the contrary, i’ll have to assume Powershell can’t do it.

            0
            • #2474 Reply
              AvatarBender

              Well, without further implementation infos I would say PowerShell can do it, because _wsystem(L"powershell.exe Write-Output 'äöüß'") works for me from external programs. So I guess there must be another issue somewhere.

              0
    • #2446 Reply
      AvatarBender

      I’ve tested this a bit and it seems indeed to be a bit tricky. I made it work from a C program using wide-character strings (see https://en.wikipedia.org/wiki/Wide_character) as console/PowerShell input, and then the PowerShell output will display Unicode characters correctly. Therefore I use _wsystem() and not system() to execute a system command, https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/system-wsystem?view=vs-2019. If something like this will work for Desktop Info certainly depends on how Desktop Info and the CMD item is implemented, but this might be a thing for you to try.

      My example C program:

      #include <stdlib.h>
      int main()
      {
          system("powershell.exe Write-Output 'äöüß'");    // <- doesn't work
          _wsystem(L"powershell.exe Write-Output 'äöüß'"); // <- OK
          return 0;
      }
      0
    • #2517 Reply
      AvatarBender

      Hi Glenn,

      in case you want to have a look on this Unicode PowerShell issue again; in Python I have to decode a stdout output from PowerShell (or cmd.exe) with code page 437 if I want to display german Umlauts correctly. The available characters with that seem to be only a small subset of Unicode, but it’s at least better than pure ASCII. Here is a small example script (works for me with both PowerShell and PowerShell Core in Python 3.8):

      import asyncio
      
      async def run_cmd(cmd):
          proc = await asyncio.create_subprocess_shell(
              cmd,
              stdout=asyncio.subprocess.PIPE,
              stderr=asyncio.subprocess.PIPE)
      
          stdout, stderr = await proc.communicate()
          print(f"output: {stdout.decode('cp437')}")
      
      asyncio.run(run_cmd("powershell.exe Write-Host -NoNewline 'äöüß'")) # PowerShell 5.1
      # asyncio.run(run_cmd("pwsh.exe -Command Write-Host -NoNewline 'äöüß'")) # PowerShell Core

      I don’t know how exactly this can be done in e.g. C/C++ though, but maybe that needs to be taken into account for enhanced PowerShell output in Desktop Info.

      0
    • #2518 Reply
      GlennGlenn
      Keymaster

      can you explain, line by line in graphic detail, what this code is doing.

      0
    • #2520 Reply
      AvatarBender

      This is basically an example from the Python docs (https://docs.python.org/3/library/asyncio-subprocess.html) about running a shell command and reading its stdout/stderr output. To get the encoding working for me was trial and error with some help from google/stackoverflow. I’ve read somewhere that ‘cp437’ seems to be the default output encoding for the Windows console in western europe. So I’m not sure if this will work for you or if the PowerShell output encoding depends on geographical location or possibly even on the Windows version. Therfore perhaps one has to detect the right font encoding of the PowerShell output first, to get a universal working implementation for this. Unicode in Windows seems to be a really nontrivial task and the source for a lot of issues.

      “asyncio” is a Python module for coroutines / nonblocking code execution

      “async def run_cmd(cmd)” declares a coroutine (function) with name “run_cmd” and a string argument with name “cmd”

      “create_subprocess_shell” is a function from the asyncio module to run a shell command, which is specified by the string argument “cmd” mentioned above

      “communicate” is a function for sending or reading data to/from that shell command through pipes

      f”output: {stdout.decode(‘cp437’)}” is string interpolation in Python: insert the value of the variable/expression inside the braces into that string. If I use {stdout} without using decode(), I get a “\x84\x94\x81\xe1” bytestring instead of “äöüß”

      “asyncio.run(run_cmd(“powershell.exe Write-Host -NoNewline ‘äöüß'”))” runs the function defined above with our PowerShell command

      0
    • #2521 Reply
      GlennGlenn
      Keymaster

      Interesting. What I get from that code is that Powershell stdout is assumed to be multibyte.

      The line containing “stdout.decode(‘cp437’)” simply assumes the stdout needs to be decoded. You decode it using a known code page. Is cp437 the default code page on the system on which you are testing this?

      I’m starting to understand that the unicode output of cmd.exe and the default output of powershell.exe are two different things. That is, cmd.exe /u is utf8 and powershell.exe by default is utf16.

      I have been using an api call IsTextUnicode which returns false on this particular text string when calling Powershell but returns true when calling cmd.exe. I believe this is because it can only detect utf8.

      However if I simply assume the output is unicode and decode it anyway, we get the correct characters from Powershell but not cmd.exe. Therefore, I can’t assume the return text from any CMD command will be decode-able, so I will have to continue testing for utf8.

      So my current plan is to add an option to CMD called ‘code-page’. If this is present the output will be decoded using the given code page. If it is not present, the IsTextUnicode test will be run. If true, the output is utf8.

      My test code looks like this:

      # test
      CMD=text:cmd.exe default,    file:cmd.exe,parameters:/c echo Hello World äöüß
      CMD=text:cmd.exe /U,         file:cmd.exe,parameters:/u /c echo Hello World äöüß
      CMD=text:cmd.exe /U cp 437,  file:cmd.exe,parameters:/u /c echo Hello World äöüß,code-page:437
      CMD=text:cmd.exe /U cp 65001,file:cmd.exe,parameters:/u /c echo Hello World äöüß,code-page:65001
      
      CMD=text:Powershell default, file:powershell.exe,parameters: Write-Host 'Hello World äöüß'
      CMD=text:Powershell cp 437,  file:powershell.exe,parameters: Write-Host 'Hello World äöüß',code-page:437
      CMD=text:Powershell cp 65001,file:powershell.exe,parameters: Write-Host 'Hello World äöüß',code-page:65001
      

      The output looks like this:

      0
    • #2523 Reply
      GlennGlenn
      Keymaster

      Additional Information:

      That last test was done on a Win 7 machine. When I run it on a Win 10 machine the cp 437 test gives the correct results.

      0
    • #2525 Reply
      AvatarBender

      The active code page for console applications, checked with the “chcp” command in a cmd.exe or powershell window on my machine is 850, and indeed the Python code from above works fine with stdout.decode(‘cp850’) as well. Apparently the mapping for these characters is the same for code pages 437 and 850. I’m on Windows 10, 1909.

      The additional ‘code-page’ option looks like a nice solution!

      0
    • #2527 Reply
      GlennGlenn
      Keymaster

      I’m on Win 10 1809. cp437 and cp850 both decode correctly.

      I suspect there is a further difference in behaviour on Win 7 compared to Win 10. Despite the active code page being 850, the decode using that page is incorrect. It’s correct using cp65001.

      0
      • #2528 Reply
        GlennGlenn
        Keymaster

        or the version of Powershell…

        0
    • #2530 Reply
      GlennGlenn
      Keymaster
    • #2533 Reply
      AvatarBender

      I’ve tested with the lastest build and it works fine for me now with the code-page option.

      Thank you very much!

      1+
Viewing 15 reply threads
Reply To: Deutsche Umlaute
Your information:




Do NOT follow this link or you will be banned from the site!