Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用-S参数接收已启动的PHP.EXE的输出?_C#_Php_.net_Command Line Interface - Fatal编程技术网

C# 如何使用-S参数接收已启动的PHP.EXE的输出?

C# 如何使用-S参数接收已启动的PHP.EXE的输出?,c#,php,.net,command-line-interface,C#,Php,.net,Command Line Interface,我正在使用从C#应用程序启动PHP.EXE: var start = new ProcessStartInfo { FileName = @"C:\PHP\v7.0\php.exe", WorkingDirectory = @"C:\temp", Arguments = "…some arguments…", WindowStyle = ProcessWindowStyle.Hidden, Redir

我正在使用从C#应用程序启动PHP.EXE:

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();
}
在为单个文件()启动PHP.EXE控制台应用程序时,这一点非常有效:

每当子进程控制台应用程序向STDOUT写入内容时,我的应用程序立即通过事件接收到它

正如所料

但是,我的C#程序在调用PHP.EXE时没有收到任何输出(即,使用内置web服务器运行)

在命令行上手动执行同样的操作,我确实会得到一个输出,与此类似:

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
这似乎无法通过我的
流程接收。启动
呼叫

我想这与PHP如何运行其内置web服务器有关

我的问题:

即使使用
-S
参数调用PHP.EXE,是否仍有机会捕获输出