在 .NET 中高效重定向标准输出
我正在尝试从 .NET 程序调用 php-cgi.exe。 我使用 RedirectStandardOutput 将输出作为流返回,但整个过程非常慢。
你知道我怎样才能让它更快吗? 还有其他技术吗?
Dim oCGI As ProcessStartInfo = New ProcessStartInfo()
oCGI.WorkingDirectory = "C:\Program Files\Application\php"
oCGI.FileName = "php-cgi.exe"
oCGI.RedirectStandardOutput = True
oCGI.RedirectStandardInput = True
oCGI.UseShellExecute = False
oCGI.CreateNoWindow = True
Dim oProcess As Process = New Process()
oProcess.StartInfo = oCGI
oProcess.Start()
oProcess.StandardOutput.ReadToEnd()
I am trying to call php-cgi.exe from a .NET program. I use RedirectStandardOutput to get the output back as a stream but the whole thing is very slow.
Do you have any idea on how I can make that faster? Any other technique?
Dim oCGI As ProcessStartInfo = New ProcessStartInfo()
oCGI.WorkingDirectory = "C:\Program Files\Application\php"
oCGI.FileName = "php-cgi.exe"
oCGI.RedirectStandardOutput = True
oCGI.RedirectStandardInput = True
oCGI.UseShellExecute = False
oCGI.CreateNoWindow = True
Dim oProcess As Process = New Process()
oProcess.StartInfo = oCGI
oProcess.Start()
oProcess.StandardOutput.ReadToEnd()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 OutputDataReceived 事件 接收数据因为它被泵送到标准输出。
You can use the OutputDataReceived event to receive data as it's pumped to StdOut.
该问题是由于 php.ini 配置错误造成的。 我遇到了同样的问题,我从以下位置下载了 Windows 安装程序: http://windows.php.net/download/< /a>.
之后并注释掉不需要的扩展,转换过程就像 Speedy Gonzales 一样,每秒转换 20 php。
您可以安全地使用“oProcess.StandardOutput.ReadToEnd()”。 它更具可读性,并且几乎与使用线程解决方案一样快。 要将线程解决方案与字符串结合使用,您需要引入一个事件或其他内容。
干杯
The problem is due a bad php.ini config. I had the same problem and i downloaded the Windows installer from: http://windows.php.net/download/.
After that and commenting out not needed extensions, the conversion process is alà Speedy Gonzales, converting 20 php per second.
You can safely use "oProcess.StandardOutput.ReadToEnd()". It's more readable and alomost as fast as using the thread solution. To use the thread solution in conjunction with a string you need to introduce an event or something.
Cheers
我发现的最佳解决方案是:
The best solution I have found is: