C# 控制台应用程序与 PHP 页面交互
我有一个 ac# 控制台应用程序,我通过 PHP 中的服务器调用来调用它,
chdir($filePath);
exec($filePath.$fileName);
效果很好,应用程序已运行。它旨在收集的数据被收集了,每个人都很高兴。 目前,我计划将一次性使用信息存储在服务器或平面文件上,但后来我注意到,当控制台应用程序正在运行并执行它的神奇操作时,页面会挂起,等待应用程序停止。这引起了我的兴趣,现在我想知道应用程序是否有办法将其数据直接传递回页面?
注意:我在 Windows 7 上运行 Apache2
更新:
最终使用
$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);
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 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的意思是“直接”,您希望应用程序的输出在其仍在运行时发送到客户端,您可能会对 passthru 感兴趣()。
如果您也是 C# 应用程序的作者,您可以跳过控制台应用程序,并以可通过 php 的 访问的方式公开功能COM 和 .Net 模块。
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.
控制台应用程序应该能够打印(使用 Console.WriteLine),并且 PHP 可以获取结果...
回到我的 PHP 时代,我们一直调用脚本(基本上只是控制台应用程序)并且有结果吐出到页面。
http://php.net/manual/en/function.shell -exec.php
[因此,唯一的区别是您应该使用
shell_exec
而不是常规的exec
]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.
http://php.net/manual/en/function.shell-exec.php
[So, the only difference is that you should use
shell_exec
instead of a regularexec
]