Home > Enterprise >  Batch - Why do I have to write in german and not english?
Batch - Why do I have to write in german and not english?

Time:06-20

I am coding a batch script to turn off Green-Ethernet in network adapter properties. I've written following code:

@echo off
cls
for /F "skip=3 tokens=1,2,3* delims= " %%G in ('netsh interface show interface') DO (
    IF "%%H"=="Disconnected" netsh interface set interface "%%J" enabled
    IF "%%H"=="Connected" netsh interface set interface "%%J" disabled
    echo %%J
    powershell.exe Set-NetAdapterAdvancedProperty -Name '%%J' -DisplayName 'Green-Ethernet' -DisplayValue 'Disabled'
    
)

My windows language is set to german, it raises this error:

Set-NetAdapterAdvancedProperty : No matching display value found. The following are valid display values: Deaktiviert,
Aktiviert
In Zeile:1 Zeichen:1
  Set-NetAdapterAdvancedProperty -Name 'Ethernet' -DisplayName 'Green-E ...
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidArgument: (MSFT_NetAdapter...CC2156B75}:...):ROOT/StandardCi...ertySettingData) [
   Set-NetAdapterAdvancedProperty], CimException
      FullyQualifiedErrorId : Windows System Error 87,Set-NetAdapterAdvancedProperty

So if I replace "Disabled" with "Deaktiviert" it works, but why does "Disabled" not work? Doesn't powershell accept english arguments on windows whose language is set to german?

CodePudding user response:

Because the executable (in this case, netsh) understands English and only English but the messages are translated to the system language for human interpretation.

Suppose the executables were to be able to accept any possible language. There would need to be possibly hundreds of different ways of expressing each and every possible parameter, like show in your example, for instance. The example instruction could be expressed in millions of different ways - interface for instance is used twice. Why couldn't you use Dutch for the first and Estonian for the second?

Even batch itself - or any programming language, would need to be able to accept any of hundreds of translations of if, not, echo, for and so on. It's simply impractical. One common string meaning one common thing, even if it's gobbledegook in any particular language - like cls is in English for instance.

Users, on the other hand, have the unreasonable attitude that they want to be able to understand the responses, so the response is tailored for the user's language. This is not simply a matter of word-for-word translation - different languages use different word-orders.

Consequently, the output that is intended to be interpreted by humans becomes a mixture of the human's language and an English-ish language, such as In Zeile:1 Zeichen:1 and CategoryInfo InvalidArgument in your example.

There's another aspect to this issue - word-order. We have a problem with dates and times. Different representations depending on language and other user-settings, like d(d)/m(m)/(cc)yy against m(m)/d(d)/(cc)yy against ccyy/mm/dd all the variations in separators. Time may have different separators, may be in 12 or 24-hour format, may have the am/pm not only as different strings, but also as string that may be separated from the numeric portion by a space, or not and with or without dots.

So, in all, your code needs to customise its interpretation of the responses that it is receiving according to the language in which it is receiving the response.

What would be a really good idea would be to allow a switch to have the response from a command to be generated in a standard way, regardless of user-language like

:: Responds in user-language
dir
set babel on
:: Responds in standard language (Probably English)
dir
set babel off
:: Back to user-language
dir

But the chances of having this are zero. Microsoft has asked for user-suggestions about enhancing the batch language years ago - so long that I've lost any links I had - but nothing has ever been converted from user-suggestion to language-change AFAIAA.

  • Related