简体   繁体   English

如何通过已经运行的Java运行命令?

[英]How to Run Commands through a already running Java?

I was wondering if it was possible to execute commands from PHP to a Java prompt which is already running? 我想知道是否有可能从PHP执行命令到已经运行的Java提示符?

I have tried the solution listed here: How to run a shell command through PHP code? 我试过这里列出的解决方案: 如何通过PHP代码运行shell命令?

and this provided no functionality 这没有提供任何功能

Let me explain 让我解释

The java is running on one screen of the linux server java在linux服务器的一个屏幕上运行

sudo apt-get install screen sudo apt-get安装屏幕

and running the .jar file through the command line. 并通过命令行运行.jar文件。

I am then running a webserver, which will have an admin accessibility to restricted areas, which will contain scrips to run specific commands through that already running .jar file? 然后我运行一个网络服务器,它将具有限制区域的管理员可访问性,它将包含通过已经运行的.jar文件运行特定命令的scrips?

You can implement some kind of IPC. 你可以实现某种IPC。 The java file listens to a port and receives the commands. java文件侦听端口并接收命令。 Or you can write the commands in a specific file which the java programm reads. 或者您可以在java程序读取的特定文件中编写命令。 I think under linux you can also use shared memory: http://www.php.net/manual/en/book.shmop.php 我认为在linux下你也可以使用共享内存: http//www.php.net/manual/en/book.shmop.php

It is possible by sending the command to the screen session. 可以通过将命令发送到屏幕会话来实现。 I used this for a minecraft server once. 我曾经将它用于一个Minecraft服务器。

screen -S <sessionname> -X stuff "<command>\r"

This would (IIRC) provide the same output as if you where inside the screen, typed the command and pressed enter. 这将(IIRC)提供相同的输出,就像您在屏幕内部,输入命令并按下回车一样。 I hope this was what you wanted. 我希望这是你想要的。

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

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