Trouble with subprocess.Popen()

Fernando frr149 at gmail.com
Sat Apr 4 09:42:04 EDT 2009


Hi,

I'm having a very strange issue with 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.

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


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?!



More information about the Python-list mailing list