Background information:
I am writing a Python application which will receive WhatsApp messages and perform some actions based on the provided commands. For that, I have installed yowsup, which is also a Python application which deals with the WhatsApp messaging.
Strategy:
Yowsup has a nice interface to send and receive messages, so my idea was to start the process via Popen and deal with the stdin, stdout and stderr. For that I wrote the code below:
from subprocess import Popen, PIPE
statement = "sudo /home/pi/yowsup/yowsup-cli demos --yowsup --config /home/pi/yowsup/config"
yowsup = Popen(statement.split(" "), stdout=PIPE, stdin=PIPE, stderr=PIPE)
while True:
output = yowsup.stdout.readline()
if output != "":
print output.rstrip()
Issue:
The code did not return any message, so I changed the statement to check if my code was fine:
statement = "ping 192.168.0.9 -c 4"
Bingo! With the command ping
the code works just great.
My question:
Why am I not able to handle the stdin and stdout by using the yowsup application and how I can make it work?
Does it play any role that yowsup is also a Python application?