I'm using something like this to start PHP.EXE from a C# application:
var start =
new ProcessStartInfo
{
FileName = @"C:\PHP\v7.0\php.exe",
WorkingDirectory = @"C:\temp",
Arguments = "…some arguments…",
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false,
};
using (var p = new Process())
{
p.StartInfo = start;
p.OutputDataReceived += (o, args) => log(args.Data);
p.ErrorDataReceived += (o, args) => log(args.Data);
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
}
This works perfectly when starting the PHP.EXE console application for a single file (the -f
parameter):
Whenever the child process console application writes something to STDOUT, my application immediately receives it through the event.
Just as expected.
However, my C# program does not receive any output when calling PHP.EXE with the -S
parameter (i.e. running with the built-in web server).
Doing the same manually on the command line, I do get an output, similar to this one:
C:\>"C:\PHP\v7.0\php.exe" -S localhost:21919 -t "C:\some\folder"
PHP 7.0.9 Development Server started at Fri Oct 14 00:46:16 2016
Listening on http://localhost:21919
Document root is C:\some\folder
Press Ctrl-C to quit.
[Fri Oct 14 00:46:17 2016] ::1:26671 [200]: /
[Fri Oct 14 00:46:17 2016] ::1:26673 [200]: /favicon.ico
[Fri Oct 14 00:46:21 2016] ::1:26675 [200]: /
[Fri Oct 14 00:46:21 2016] ::1:26676 [200]: /favicon.ico
This seems to be not receivable through my Process.Start
call.
I guess that it is related due how PHP runs its built-in web server.
My question:
Is there any chance to still capture the output, even if PHP.EXE is called with the -S
parameter?