I have a Python Server finally working and responding to several commands with output, however I now have a problem with PHP receiving the full output. I tried commands like fgets, fread, the only command that seems to work is "fgets".
However, this only works in the data row, after which I created a while statement, shown below:
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
However, it seems that the Python server is not sending Feof at the end of the output, so the php page is not working and does not display anything. As I said above, it just launches echo fgets ($ handle), it works fine and displays one line, again running the command under nothing displays the next line etc
I have attached an important part of my Python Script below:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", port))
s.listen(5)
print "OK."
print " Listening on port:", port
import subprocess
while 1:
con, addr = s.accept()
while True:
datagram = con.recv(1024)
if not datagram:
break
print "Rx Cmd:", datagram
print "Launch:", datagram
process = subprocess.Popen(datagram+" &", shell=True, stdout=subprocess.PIPE)
stdout, stderr = process.communicate()
con.send(stdout)
con.close()
s.close()
I also added a full PHP script:
<?php
$handle = fsockopen("tcp://xxx.xxx.xxx.xxx",12345);
fwrite($handle,"ls");
echo fgets($handle);
fclose($handle);
?>
Thanks Ashley