简体   繁体   中英

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?

I have tried the solution listed here: How to run a shell command through PHP code?

and this provided no functionality

Let me explain

The java is running on one screen of the linux server

sudo apt-get install screen

and running the .jar file through the command line.

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?

You can implement some kind of IPC. The java file listens to a port and receives the commands. Or you can write the commands in a specific file which the java programm reads. I think under linux you can also use shared memory: 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.

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. I hope this was what you wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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