从 .NET 启动进程但 RedirectedStandardOutput 不支持 UTF-8
我正在尝试使用以下代码从.NET 调用 php 的 HTML 净化器:
Process myProcess = new Process();
myProcess.StartInfo.FileName = "C:\Path\to\php.exe";
myProcess.StartInfo.Arguments = "C:\Path\to\purify.php";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
String inputText;
inputText = txtCodes.Text;
if (inputText.Length > 0)
{
myStreamWriter.Write(inputText);
}
myStreamWriter.Close();
labMsg.Text = myProcess.StandardOutput.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
.. 一切正常,除了...我无法取回非 asci 字符。 例如,在输入中提供一些韩语字符会返回问号作为输出。
即使 HTMLPurifier 函数被绕过,并且我只是尝试简单地提供输入 .NET,将其存储在 php 变量中,并将该变量回显回输出,也会发生这种情况。
有任何想法吗?
I am trying to call php's HTML purifier from .NET using this code:
Process myProcess = new Process();
myProcess.StartInfo.FileName = "C:\Path\to\php.exe";
myProcess.StartInfo.Arguments = "C:\Path\to\purify.php";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
String inputText;
inputText = txtCodes.Text;
if (inputText.Length > 0)
{
myStreamWriter.Write(inputText);
}
myStreamWriter.Close();
labMsg.Text = myProcess.StandardOutput.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
.. and all works fine except ... I am not able to get back non-asci characters. For example providing some Korean characters in the input returns questionmarks as output.
This happens even if the HTMLPurifier function is bypased and I am just trying to simple provide the input .NET, store it in php variable, and echo that variable back to output.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢指点。 我确实设法解决了它。 问题是为输入和输出显式指定 UTF-8。 最后,沃金代码如下所示:
Thanks for the pointer. I did actually managed to solve it. The catch was to explicitly specify UTF-8 for BOTH input and Output. In the end the woking code looks like this:
尝试
Try