Sign Up

Details

Hello,

I'm french and on my french OS, commands returns are localized... and some caracters are not properly handled in StdOutput/StdError streams. For instance, with the ping example, I expect to get five "Réponse de 127.0.0.1...", and I get instead "R,ponse de 127.0.0.1..." (é is replaced by ,). This is only one example, others accentuated characters are not properly returned.

I've alreayd played with .Net, and I know it is possible to set encoding. In my case, using the CodePage 850, returned strings are just fine, with expected accentuated caracters.

So I'm convinced that having the default system encoding set in the @created VI should be a nice imporvement.

Option A. Add an optional parameter
It is possible to set it statically, or by passing the numeric CodePage value as an argument (if not specified, use defaut value).
It also ca be a ring, with human readable description of CodePage. But choosing the right encoding, in my case between ibm850/Western Europe (DOS), ibm852/Central Europe (DOS), IBM1147/IBM EBCDIC (France-Euro), has nothing straightforward for a developer (I mean, by someone non familiar with CodePages). See https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=net-5.0

Option B : Find a way to get the system CodePage programmatically
Instead of having one more parameter (even optional) or wondering what is tmy OS encoding, if the @create vi can handle this for me, that's perfect. Not so straightforward.

I find a post on StackOverflow that describes how the get the system default codepage (https://stackoverflow.com/questions/61211164/how-to-find-os-code-page-number-in-net-core). I managed to translate it into LabVIEW code, but it always returns the default CodePage 1252 / Western European (Windows), that returns me wrong caracters.

As last resort, I've build a code that launches cmd.exe with .Net connectivity functions, and executes the chcp command (https://docs.microsoft.com/fr-fr/windows-server/administration/windows-commands/chcp). With a bit of string parsing, I managed to get the numeric CodePage value, and to apply it to StartInfo, as StandardOutputEncoding and StandardErrorEncoding. But I found this method a bit messy.

What do you think about this ? Does someone have a better way to get the correct CodePage programmatically ?

Best regards,

Comments

Javier Ruiz Hi Mathieu. Thanks for the message. So far Option A seems like a good step forward to me, even if you have to manually pass the CodePage value. Looking forward to hear if other people have more comments, but I can try to look into this in the next few days.
  1
 •  Reply3 years
Mathieu Reyrolle Hi Javier, I found an other way to get the OEM code page using registry (see https://serverfault.com/questions/80635/how-can-i-manually-determine-the-codepage-and-locale-of-the-current-os/836221). As far as this .Net class is targeting LabVIEW on Windows, it should work nicely. I'm totally new to GitHub, I just try to make a Pull Request (first time using Git). Hoping it will be usable from your side.
 •  Reply3 years

Please sign in to leave a comment.