C# System.Diagnostics.ProcessStartInfo 环境变量不区分大小写?
当我向其中插入内容时,ProcessStartInfo.EnvironmentVariables(类型StringDictionary
)中的EnvironmentVariables 始终设置为小写。例如:
proc.StartInfo.EnvironmentVariables.Clear();
proc.StartInfo.EnvironmentVariables.Add("REDIRECT_STATUS", "");
// [snipped more variables being added here]
proc.Start();
在该过程中现在有一个 redirect_status
,而不是我想要的 REDIRECT_STATUS
。这会导致问题。
我已经在其他地方读到过,您可以通过制作批处理文件来解决这个问题,但这不适用于我的情况,因为这意味着用作 CGI(此代码可能每秒被调用 10 次。
)有没有办法让 EnvironmentVariables
不区分大小写,而只允许我全部大写?
The EnvironmentVariables in ProcessStartInfo.EnvironmentVariables (type StringDictionary
) are always set to lower-case when I insert something into it. For example:
proc.StartInfo.EnvironmentVariables.Clear();
proc.StartInfo.EnvironmentVariables.Add("REDIRECT_STATUS", "");
// [snipped more variables being added here]
proc.Start();
In the process there now is a redirect_status
, and not a REDIRECT_STATUS
as I wanted. This causes problems.
I already read somewhere else that you could get around this issue by making a batch file, however this is not applicable in my case, as this is meant to be used as CGI (this code could potentially be called 10 times a second.)
Is there a way to get the EnvironmentVariables
to not be case insensitive, and just allow me to go all-caps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,请注意所有也遇到此问题的人:显然,这是 .Net 3.5 中的一个错误 并在 4.0 中修复。
我不得不切换到 .Net 4.0 来解决这个问题。
Hmm, note to everybody out there who's also having this problem: Apparantly, this is a bug in .Net 3.5 and is fixed in 4.0.
I had to switch to .Net 4.0 to resolve this issue.
Windows 中的环境变量不区分大小写。这个变量的行为显然是基于这个事实。如果您在 Windows 环境中使用环境变量,这不会造成问题。你没有提到它在什么平台上——它是一个在类 Unix 系统上运行的 Mono 应用程序吗?
Environment variables in Windows are case insensitive. The behavior of this variable is clearly based on that fact. If you are using environment variables in a Windows environment, this shouldn't cause trouble. You don't mention what platform this is on - is it a Mono application running on a Unix-like system?
我遇到了同样的问题并发现了这个问题。此时不想将项目升级到 .Net 4,我找到了以下解决方法。此解决方法取决于 StringDictionary 类的内部实现,这样做通常被认为是不好的做法,但它可以在 .Net 2 上完成工作...
I ran into the same problem and found this question. Not wanting to upgrade the project to .Net 4 at this point, I found the following workaround. This workaround depends on the internal implementation of the StringDictionary class, and doing so is often considered bad practice, but it gets the job done on .Net 2...