Use Python to handle the STDIN and STDOUT of a C++ Program
<p>I have program A which is a command line application that prints out specific status messages at random times. It also takes input and runs commands based on that. What I'm trying to do is use Python to make a wrapper around that program so that when the output (stdout) meets specific criteria, a python function is run. I also have a function that will send input to Program A based on Slack- I'm using the slackhq/python-slackclient rtm_connect() to listen to a channel. However, when I run my handler, the STDIN/STDOUT don't appear (STDOUT is being sent to PIPE because of a guide), and when I manually trigger events that meet the criteria for the first python function, nothing happens. No print statement, nothing.</p>

<p>Pexpect keeps hitting <code>pexpect.TIMEOUT: Timeout exceeded.</code></p>

<pre><code>a = Popen(["/proj/a"], stdout=PIPE)

def main():
    sc.rtm_connect() #The RTM connect
    a_to_slack(test_message) #Post message when connected

    if a:
        print("A was opened previously")
        listen_to_a()
    else:
        world = Popen(["/proj/a"], stdout=PIPE)
        listen_to_a()

def listen_to_a():
    while True:
        data, error = a.stdout.read()[0] #From duplicate, to get STDOUT
        print(data) #Never prints
        a_to_slack(data) #Nothing..
        print sc.rtm_read() #Doesn't print here either
        time.sleep(1)
</code></pre>