Hello,
I have a Python Server finally working and responding to multiple command's with the output's, however I'm now having problem's with PHP receiving the full output. I have tried commands such as fgets, fread, the only command that seems to work is "fgets".
However this only recieve's on line of data, I then created a while statement shown bellow:
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
However it seems the Python server is not sending a Feof at the end of the output so the php page times out and does not display anything. Like I said above, just running echo fgets($handle), work's fine, and output's one line, running the command again under neither will display the next line e.t.c
I have attached the important part of my Python Script bellow:
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 have also attached the full PHP script:
<?php
$handle = fsockopen("tcp://xxx.xxx.xxx.xxx",12345);
fwrite($handle,"ls");
echo fgets($handle);
fclose($handle);
?>
Thanks, Ashley