是否Process.StartInfo.Arguments支持UTF-8字符串? [英] Does Process.StartInfo.Arguments support a UTF-8 string?

查看:502
本文介绍了是否Process.StartInfo.Arguments支持UTF-8字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用UTF-8字符串作为参数的StartInfo的?

Can you use a UTF-8 string as the Arguments for a StartInfo?

我试图传递一个UTF-8(在这种情况下,日本的字符串)到应用程序作为控制台参数。

I am trying to pass a UTF-8 (in this case a Japanese string) to an application as a console argument.

像这样的东西(这只是一个例子!(cmd.exe的将是一个自定义应用程序))

Something like this (this is just an example! (cmd.exe would be a custom app))

var process = new System.Diagnostics.Process();
process.StartInfo.Arguments = "/K \"echo これはテストです\"";
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = true;

process.Start();
process.WaitForExit();



执行这个看似松散的UTF-8字符串和所有的目标应用程序看到的是回声? ???????

Executing this seems to loose the UTF-8 string and all the target application sees is "echo ?????????"

在命令行中直接执行此命令(通过粘贴参数)目标应用正确接收的字符串,即使命令行本身似乎并不正确显示。

When executing this command directly on the command line (by pasting the arguments) the target application receives the string correctly even though the command line itself doesn't seem to display it correctly.

我需要做什么特别的,以便能够在参数UTF-8支持或者这只是不支持?

Do I need to do anything special to enable UTF-8 support in the arguments or is this just not supported?

推荐答案

这完全取决于你试图启动该程序。 Process类完全支持Unicode,象操作系统。但该方案可能是老,并使用8位的字符。它将使用GetCommandLineA()来检索命令行参数,ANSI版本的原生的Unicode GetCommandLineW()API函数。并转化Unicode字符串使用系统默认代码页在控制面板+区域和语言选项,语言对于非Unicode程序配置的8位字符。使用CP_ACP调用WideCharToMultiByte()。

It completely depends on the program you are trying to start. The Process class fully supports Unicode, as does the operating system. But the program might be old and use 8-bit characters. It will use GetCommandLineA() to retrieve the command line arguments, the ANSI version of the native Unicode GetCommandLineW() API function. And that translates the Unicode string to 8-bit chars using the system default code page as configured in Control Panel + Regional and Language Options, Language for Non-Unicode Programs. WideCharToMultiByte() using CP_ACP.

如果不是日语代码页,即翻译产生问号,因为日语字型只有在日本代码页中的代码。切换系统代码页通常不是非日语的人非常可取的。 UTF8肯定是行不通的,程序是不会指望他们。考虑运行此程序在虚拟机中。

If that is not the Japanese code page, that translation produces question marks since the Japanese glyphs only have a code in the Japanese code page. Switching the system code page isn't usually very desirable for non-Japanese speakers. Utf8 certainly won't work, the program isn't going to expect them. Consider running this program in a virtual machine.

这篇关于是否Process.StartInfo.Arguments支持UTF-8字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆