检测终端是现代的“Terminal”应用还是常规的“Command Prompt”在C#中

huangapple go评论68阅读模式
英文:

Detecting whether the terminal is the modern 'Terminal' app, or the regular 'Command Prompt' in csharp

问题

The modern 'Terminal' app from the Windows Store supports features that the classic 'Command Prompt' application does not. I'm looking for a way to detect which my application is running in so that I can drop down the features used within the console as appropriate.

英文:

The modern 'Terminal' app from the Windows Store supports features that the classic 'Command Prompt' application does not. I'm looking for a way to detect which my application is running in so that I can drop down the features used within the console as appropriate.

答案1

得分: 1

你可以查找"WT_SESSION"环境变量,参见此功能请求

if (Environment.GetEnvironmentVariable("WT_SESSION") != null)
{
// 在Windows终端中运行
}

英文:

You can look for the "WT_SESSION" environment variable, see this Feature Request.

if (Environment.GetEnvironmentVariable("WT_SESSION") != null)
{
    // running in Windows Terminal
}

huangapple
  • 本文由 发表于 2023年4月17日 06:15:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定