Does Process.StartInfo.Arguments support a UTF-8 string?

后端 未结 4 1940
孤街浪徒
孤街浪徒 2020-12-17 16:47

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

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

4条回答
  •  被撕碎了的回忆
    2020-12-17 17:06

    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.

    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.

提交回复
热议问题