批次 - 为什么我必须用德语而不是英语写作?

发布于 2025-02-08 16:06:11 字数 1152 浏览 1 评论 0原文

我正在编码一个批处理脚本,以关闭网络适配器属性中的绿色以上。 我已经编写了以下代码:

@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'
    
)

我的Windows语言设置为德语,这会引发此错误:

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

因此,如果我用“ Deaktiviert”替换“禁用”它的工作原理,但是为什么“禁用”不起作用? Powershell不接受将语言设置为德语的窗口上的英语论点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

︶葆Ⅱㄣ 2025-02-15 16:06:11

因为可执行文件(在这种情况下,netsh)只能理解英语,但这些消息被转换为系统语言进行人类解释。

假设可执行文件能够接受任何可能的语言。例如,在您的示例中,可能需要数百种不同的方式来表达每个可能的参数,例如show。示例指令可以以数百万种不同的方式表示 - 接口使用两次。为什么您不能将荷兰人用于第一个和第二次的爱沙尼亚人?

即使批次本身或任何编程语言,也需要能够接受,不是,echo,的数百个翻译中的任何一个代码> 等等。这简直是​​不切实际的。一个常见的字符串意味着一个常见的事物,即使它是任何特定语言的gobbledegook,例如cls是英语。

另一方面,用户的态度不合理,他们希望能够理解响应,因此响应是针对用户语言量身定制的。这不仅仅是单词翻译的问题 - 不同的语言使用不同的单词词。

因此,旨在由人类解释的输出成为人类语言和英语语言的混合,例如Zeile中的:1 Zeichen:1 and 类别InvalidArgument 在您的示例中。

这个问题还有另一个方面 - 单词order。我们在日期和时间有问题。不同的表示根据语言和其他用户安排,例如针对m(m)/d(m)/d(d)/(cc)/(cc)/(cc)yy,例如d(d)/m(m)/(cc)yy分离器的变化。时间可能具有不同的分离器,可能是12或24小时的格式,不仅具有am/pm,不仅是不同的字符串,而且还可以通过空间与数字部分分开的字符串,无论是否没有点。

因此,总的来说,您的代码需要自定义其对根据收到响应的语言收到的响应的解释。

一个真正的好主意是,无论用户语言如何,允许开关以标准方式生成命令的响应,

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

但是拥有此命令的机会为零。微软已经要求使用用户探索来增强几年前的批处理语言 - 这么长时间以至于我失去了任何链接 - 但是从来没有从用户 - 探索转换为语言变换的AFAIAA。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文