Trouble with subprocess.Popen()

Discussion in 'Python' started by Fernando, Apr 4, 2009.

  1. Fernando

    Fernando Guest

    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?!
     
    Fernando, Apr 4, 2009
    #1
    1. Advertising

  2. On Sat, 4 Apr 2009 06:42:04 -0700 (PDT), Fernando <>
    declaimed the following in gmane.comp.python.general:

    >
    > Every time you call this external exe, it will return a different
    > string. However, if I call it several times using Popen, it will


    Does it? Have you tried using a command line shell?
    >
    > args = [C_KEY_MAKER, '/26', USER_NAME, ENCRYPTION_TEMPLATE, '0', ]


    >
    > What on Earth am I doing wrong?!


    Calling something that appears to take a line of user supplied
    parameters for the purpose of generating a unique key -- a key
    apparently based upon the arguments and you don't show us what those are
    -- which should be identical for the same arguments. After all, if
    putting the SAME arguments into a process results in different output,
    you have a random number generator (and don't even need the arguments).

    I presume, somewhere in the code, you have defined values for:
    C_KEY_MAKER, USER_NAME, and ENCRYPTION_TEMPLATE.
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Apr 4, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michele Simionato

    subprocess.Popen

    Michele Simionato, Dec 12, 2004, in forum: Python
    Replies:
    5
    Views:
    17,781
  2. Ivo Woltring
    Replies:
    4
    Views:
    3,621
    Jeff Shannon
    Jan 27, 2005
  3. John Abel
    Replies:
    2
    Views:
    3,457
    John Abel
    May 12, 2005
  4. nik

    subprocess popen trouble

    nik, Jul 10, 2007, in forum: Python
    Replies:
    1
    Views:
    584
    Nick Craig-Wood
    Jul 10, 2007
  5. File.popen/IO.popen

    , May 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    272
    Robert Klemme
    May 20, 2006
Loading...

Share This Page