I use SSH2 library for my web application and I am trying to get python "print()" results from the code. The problem is when, I connect to SSH2 and do stream_get_contents to get the output into a variable, it doesn't show the python print("") output. There is no output from the python. When I run the script via ssh I get the python print. I need to get the python output into a PHP variable. I've found when I do bash echo "test", it outputs on ssh2. That is what I need but from a python script. Could someone please help as I've been trying to fix this all night.
Executing any bash script with echo works. But when using python output, it doesn't go into the same echo type or whatever.
// PHP API Script, should return with the code from python script
$stream = ssh2_exec($connection, "python -u fetch.py 0000 test");
// Stripped Python Script, I've tried all the possible outputs. It should output like bash "echo test"
#subprocess.call('echo 0',shell=True)
if elems[0].is_displayed():
print("Game PIN not valid!")
subprocess.call('echo invalid',shell=True)
sys.stdout.write("invalid")
sys.stdout.flush()
else:
print ("Game PIN is valid!")
subprocess.call('echo valid',shell=True)
sys.stdout.write("valid")
sys.stdout.flush()
I get nothing for output because python or SSH2 isn't keeping the connection alive because the python script is separate from the stream. The SSH2 just executes the script but doesn't return any outputs. Using "echo" returns the result because that is the command to return. I need to get the python output into a PHP variable so I can execute it elsewhere.