开发者

c# console application interacting with PHP page

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

chdir($filePath);
exec($filePath.$fileName);

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开发者_如何学Go 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


Update:

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;
json_decode($output);


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.


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"

http://php.net/manual/en/function.shell-exec.php

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜