tags:

views:

31

answers:

3

I have a java server application that, when its running, you can interact with it sending commands via stdin. I want to write a web interface that can send these commands to it.

In order to do that I need some way of getting commands from php to the stdin for this backgrounded job. Is there a way to do this from console? or possibly write some kind of wrapper that controls the server job and can access its stdin ? could this be done in python?

A: 

You could connect its stdin to a FIFO and then have another daemon also connect to the FIFO and send commands. It might be better to have the control daemon start the Java daemon though, so that the Java daemon doesn't shut down if the control daemon does for some reason.

Ignacio Vazquez-Abrams
A: 

You can use python subprocess module:

Example of calling external shell command:

from subprocess import call

try:
    retcode = call("mycmd" + " myarg", shell=True)
    if retcode < 0:
        print >>sys.stderr, "Child was terminated by signal", -retcode
    else:
        print >>sys.stderr, "Child returned", retcode
except OSError, e:
    print >>sys.stderr, "Execution failed:", e
Dominik Szopa
A: 

you could use the command line, something like this

wrapper.php (using backticks)

$cmd = `php /path/to/background_script.php &`;
echo $cmd;

background_script.php

echo "Hello world in 5 seconds\n";
sleep(5);
echo "Hello again\n";
Phill Pafford