I'm trying to get the PHP parser to run a page and then return the results to my server, however when I run the command via my code, it returns nothing. I know the command is correct because if I run it manually with the same path, it works fine. Heres my code:
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.