PHP bir. Net Programı bellek veri geçmek

4 Cevap ûnet

A. Net programa veri in memory PHP geçmek için? I Process php.exe aramak için kullandığınız, ve script adı (*. Php) ve argümanları geçecek.

Sorun şimdi nasıl ben PHP. Net, verileri geri pas yapmak nedir?

Özellikle, ben Net onu durdurmak böylece. PHP verilerini geçebileceği şekilde bakıyorum. . Net kod ben buna benzer var:

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();

Edit: Some suggest the use of XML, which is fine. But XML is a file based system; I would prefer a manner in which the interaction of data are passed in memory, just to prevent accidentally writing to the same XML file.

4 Cevap

Iyileştirilmesi Inspire's solution, burada tam kodu:

PHP:

<?php

$stdout = fopen('php://stdout', 'w');
$writeString ="hello\nme\n";
fwrite($stdout, $writeString);
fclose($stdout);

. Ve burada Net kod:

[Test]
public void RunConsole()
{
    Process p = new Process();

    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = @"C:\Program Files\PHP\php.exe";
    p.StartInfo.Arguments = "\"C:\\Documents and Settings\\test\\My Documents\\OurPHPDirectory\\OutputData.php\"";
    p.Start();
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    Assert.AreEqual(0, p.ExitCode);
    Assert.AreEqual("hello\nme\n", output);

}

Sen STDOUT PHP ile bir akışı kullanabilirsiniz:

<?php
$stdout = fopen('php://stdout', 'w');

Ve sonra içinde. NET yakalama çıktı. . Ben NET ile fazla deneyimim yok ama bu bir sürecin çıktısını yakalamak için izin görünür:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

Farklı uygulamalara veri geçen tercih edilen yolu XML. ArsenMkrt bir webcoder yoluyla belirtildiği gibi bir dosya biçiminde olabilir, ya da.

Bu tekniği kullanarak hemen hemen her teknoloji veri işlemek mümkün olacaktır eminiz.

Ben PHP bilmiyorum, ama, web hizmetleri ile çalışmak net programı ile çalışır. Net web servisi yazmak ve bu hizmet için php sunucusu verileri geçmek özelliğine sahip olacağını düşünüyorum