c#console应用程序与PHP页面交互

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);
donglanzhan7151
donglanzhan7151 悬挂我不介意。控制台应用程序不需要很长时间,但我正在为移动平台设计它。也许呢?
接近 9 年之前 回复
doufenpaiyu63706
doufenpaiyu63706 您是否正在寻找一种c#控制台应用程序可以与PHP解释器通信的方式(没有“挂起”)?如果是,您是否正在寻找某种基于IPC的解决方案?
接近 9 年之前 回复

2个回答



如果您想“直接”表示您希望应用程序的输出在仍在运行时发送到客户端,您可能会对 passthru()

如果你也是C#应用程序的作者,你可以跳过控制台应用程序 并通过php的 COM和.Net模块以可访问的方式公开功能。</ p>
< / DIV>

展开原文

原文

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可以获取结果... </ p>

回到我的PHP时代,我们一直调用脚本(基本上只是控制台应用程序)并将结果吐出到页面。</ p>


“shell_exec - 通过shell执行命令并将完整输出
作为字符串返回”</ p>
</ blockquote>

http://php.net/manual/en/function.shell-exec.php </ p> \ n

[所以,唯一的区别是你应该使用 shell_exec </ code>而不是常规 exec </ code>] </ p>
</ div>

展开原文

原文

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]

douguanya6399
douguanya6399 我遇到了这个命令的麻烦。 我在cmd提示符下运行它时工作。 echo shell_exec(“cd D:/ ScanBoyConsole && D:/ScanBoyConsole/ScanBoy_Console.exe'COM1'9600 8 1 0 1”); 但是当我这样称它时程序崩溃了。 我没有设置CWD之前遇到过这个问题..有什么想法吗?
接近 9 年之前 回复
duanmo7075
duanmo7075 我可以返回php变量吗? Console.WriteLine(“$ foo ='bar';”);
接近 9 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐