Python's subprocess.Popen returns the same stdout even though it shouldn't
Question: I'm having a very strange issue with Python's subprocess.Popen. I'm using it
to call several times an external exe and keep the output in a list.

Every time you call this external exe, it will return **a different string**.
However, if I call it several times using Popen, it will always **return the
SAME string**. =:-O

It looks like Popen is returning always the same value from stdout, without
recalling the exe. Maybe doing some sort of caching without actually calling
again the exe.

This is my code:

    
    
    def get_key():
    
        from subprocess import Popen, PIPE
    
        args = [C_KEY_MAKER, '/26', USER_NAME, ENCRYPTION_TEMPLATE, '0', ]
        process = Popen(args, stdout=PIPE)
        output = process.communicate()[0].strip()
        return output
    
    if __name__ == '__main__':
        print get_key() # Returns a certain string
        print get_key() # Should return another string, but returns the same!
    

What on Earth am I doing wrong?!


Answer: It is possible (if `C_KEY_MAKER`'s random behaviour is based on the current
time in seconds, or similar) that when you run it twice on the command line,
the time has changed in between runs and so you get a different output, but
when python runs it, it runs it twice in such quick succession that the time
hasn't changed and so it returns the same value twice in a row.

