Benim kod üzerinden komutu çalıştırdığınızda, ancak hiçbir şey verir, bir sayfa çalıştırın ve sonra benim sunucuya sonuçlarını döndürmek için PHP çözümleyici almaya çalışıyorum. Ben aynı yolu ile el çalıştırırsanız, iyi çalışıyor, çünkü komut doğru olduğunu biliyorum. Buyrun bu benim kodu:
var p = new Process
{
StartInfo = new ProcessStartInfo("C:\\xampp\\php\\php.exe", path)
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
var output = new StringWriter();
var error = new StringWriter();
p.OutputDataReceived += (sender, args) => output.WriteLine(args.Data);
p.ErrorDataReceived += (sender, args) => error.WriteLine(args.Data);
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
if (p.ExitCode != 0)
{
throw new Exception(string.Format(
"PHP failed with the following output:{0}{1}",
/* {0} */ Environment.NewLine,
/* {1} */ error.GetStringBuilder().ToString()));
}
var res = output.GetStringBuilder().ToString();
Console.WriteLine(res);
EDIT: With this current code, it throws the exception in the code with no output.