简体   繁体   English

是否可以在 PHP 的正在运行的 C# 程序中运行命令?

[英]It is possible to run a command in a running C# program from PHP?

I have a C# console application program running on windows server anytime.我有一个 C# 控制台应用程序随时在 windows 服务器上运行。
On the same machine I have zend server and apache running.在同一台机器上,我运行了 zend 服务器和 apache。

It is possible to send a command to the running C# program directly from the PHP without having an endless loop on the C# program that taking the info from outsourced files?可以直接从 PHP 向正在运行的 C# 程序发送命令,而不会在 C# 程序上从外包文件中获取信息的无限循环?

For example, the command "/init" would initialize all the variables on the C# program.例如,命令“/init”将初始化 C# 程序上的所有变量。
Can I write a init.php file to send the "/init" command to the running C# windows application?我可以编写一个 init.php 文件来将“/init”命令发送到正在运行的 C# windows 应用程序吗?
This will be in order to initialize all the variables on the running "Program.exe" by opening the URL " http://example.com/init.php ".这是为了通过打开 URL “ http://example.com/init.php ”来初始化正在运行的“Program.exe”上的所有变量

Thanks in advance.提前致谢。

There is a number of approache for IPC . IPC有多种方法。

As I understand it, you want to do that without a loop.据我了解,您希望在没有循环的情况下做到这一点。 The thing is: You have to have a loop anyway to keep the console application alive.问题是:无论如何,您都必须有一个循环才能使控制台应用程序保持活动状态。 The programm is staretd.该程序已启动。 Executes all code.执行所有代码。 And then ends.然后结束。 You could block it via stuff like ReadKey(), but then it would not be able to process anything.你可以通过 ReadKey() 之类的东西来阻止它,但是它不能处理任何东西。

Unfortunately all approaches to IPC I know either require a loop.不幸的是,我知道的所有 IPC 方法都需要一个循环。 Or a GUI that already has a loop - the EventQueue.或者一个已经循环的 GUI - EventQueue。 You will not get around some multitasking, and for that alone I always advise a GUI application.您将无法绕过一些多任务处理,仅此一项我总是建议使用 GUI 应用程序。

It is also pretty unclear what data you actually want to send and what that application doe with that data.还不清楚您实际要发送哪些数据以及该应用程序如何处理该数据。 Depending on those requirements, it might be possible to just do this via commandline parameters.根据这些要求,可能只通过命令行参数来执行此操作。

However the biggest issue might be rights.然而,最大的问题可能是权利。 Web Servers are notoriously vulnerable to hacking, being online 24/7/365. Web 服务器是出了名的容易受到黑客攻击,24/7/365 在线。 As a result, they are usually run under the most restrictive user rights imaginable.因此,它们通常在可以想象的最严格的用户权限下运行。 Read access to it's content and programm folder is the only thing you can asume.对其内容和程序文件夹的读取权限是您唯一可以承担的。 Reading anywhere else, writing or even Execution is not usually on the list of things it can do.在其他地方阅读、写作甚至执行通常不在它可以做的事情的清单上。 And will raise some eyebrows from the admin too.并且也会引起管理员的注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM