如何将内存中的数据从 PHP 传递到 .Net 程序?我会用Process调用 php.exe,并传入脚本名称 (*.php) 和参数。
现在的问题是如何将数据从 PHP 传回 .Net?
具体来说,我正在研究 PHP 传递数据的方式,以便 .Net 可以拦截它。我拥有的 .Net 代码与此类似:
Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;
ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
var text1 = sr.ReadToEnd(); // the php output should be able to be read by this statement
sw.Close();
编辑:有些人建议使用 XML,这很好。但是 XML 是一个基于文件的系统;我更喜欢在内存中传递数据交互的方式,只是为了防止意外写入同一个 XML 文件。
最佳答案
您可以将流与 PHP 一起使用到 STDOUT:
<?php
$stdout = fopen('php://stdout', 'w');
然后在 .NET 中捕获输出。我对 .NET 没有太多经验,但这似乎允许您捕获进程的输出:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
关于.net - 将内存中的数据从 PHP 传递到 .Net 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1476206/