2011-08-31 13:29 阅读 134


I have a c# console application that I invoke with a server call in PHP


This works great, the application is run. The data it is designed to collect is collected and everyone is happy. Currently I have plans on storing the one time use information on a server or a flat file, but then I noticed that while the console application is running and doing it's magic the page hangs waiting for the application to stop. This intrigued me, and now i'm wondering if there is a way for the application to pass it's data back to the page directly?

Note: I'm running Apache2 on Windows 7


Ended up using

$runCommand = "D:\\ScanBoyConsole\\ScanBoy_Console.exe COM1 9600 8 1 0 1"; 
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dtgvl48608 dtgvl48608 2011-08-31 13:39

    If you mean by "directly" that you want the application's output sent to the client while it's still running you might be interested in passthru().
    If you're also the author of the C# application you could skip the console application and expose the functionality in a way accessible via php's COM and .Net module.

    点赞 评论 复制链接分享
  • doufu7835 doufu7835 2011-08-31 13:31

    The console app should be able to print (using Console.WriteLine), and PHP can take the results of that...

    Back in my PHP days, we called scripts all the time (that are nothing but console apps basically) and had the results spit out to the page.

    "shell_exec — Execute command via shell and return the complete output as a string"


    [So, the only difference is that you should use shell_exec instead of a regular exec]

    点赞 评论 复制链接分享