How to use PHP CLI in C#

前端 未结 1 1279
执笔经年
执笔经年 2021-01-22 23:12

I\'m from China, so my english maybe is really poor. I will try my best to make you understand my question. I want to use PHP CLI in my C# project. I tried code like this

<
相关标签:
1条回答
  • 2021-01-22 23:48

    If I go by your code example the question does not make sense. However according to your question you can execute a PHP script from the CLI and collect the output using something like the following:

    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    string sOutput = "";
    
    proc.EnableRaisingEvents = false;
    proc.StartInfo.FileName = "php.exe";
    proc.StartInfo.Arguments = "-f file.php";
    proc.StartInfo.RedirectStandardOutput = true;
    
    System.IO.StreamReader hOutput = proc.StandardOutput;
    
    proc.WaitForExit(2000);
    
    if(proc.HasExited)
       sOutput = hOutput.ReadToEnd();           
    

    Half of this code is my own and the rest I derived from a snippet I found via Google.

    Hopefully this is what you are looking for.

    0 讨论(0)
提交回复
热议问题