Using wildcards with Popen in the Subprocess module

Discussion in 'Python' started by William Hudspeth, Mar 15, 2007.

  1. Hello,

    I am needing to pass an argument to the Popen function of the Subprocess
    module that includes a wildcard in the filename. It seems that Popen is
    not able to expand wildcards, and treats a filename that includes a
    wildcard as a literal.

    EX.

    var1="/path_to_files/filnames*.doc"
    result=Popen(["command",var1]).wait()

    Can anyone tell me how I can work around this problem?


    Thanks, Bill
    William Hudspeth, Mar 15, 2007
    #1
    1. Advertising

  2. William Hudspeth

    Guest

    On Mar 15, 2:04 pm, William Hudspeth <> wrote:
    > Hello,
    >
    > I am needing to pass an argument to the Popen function of the Subprocess
    > module that includes a wildcard in the filename. It seems that Popen is
    > not able to expand wildcards, and treats a filename that includes a
    > wildcard as a literal.
    >
    > EX.
    >
    > var1="/path_to_files/filnames*.doc"
    > result=Popen(["command",var1]).wait()
    >
    > Can anyone tell me how I can work around this problem?
    >
    > Thanks, Bill


    What are you doing, exactly? IF you are just passing in a random
    filename, you could do something like this:

    var1 = "/path_to_files_/%s" % (filename)

    where filename is another variable.

    You might also look into using os.system which allows just about any
    command line options to be used.

    Hope this helps.

    Mike
    , Mar 15, 2007
    #2
    1. Advertising

  3. William Hudspeth

    Fabio FZero Guest

    You could use glob and expand the resulting list to astring manually,
    but you have to make sure the command accepts the "command file1 file2
    file3..." format.

    FZero

    On Mar 15, 4:04 pm, William Hudspeth <> wrote:
    > Hello,
    >
    > I am needing to pass an argument to the Popen function of the Subprocess
    > module that includes a wildcard in the filename. It seems that Popen is
    > not able to expand wildcards, and treats a filename that includes a
    > wildcard as a literal.
    >
    > EX.
    >
    > var1="/path_to_files/filnames*.doc"
    > result=Popen(["command",var1]).wait()
    >
    > Can anyone tell me how I can work around this problem?
    >
    > Thanks, Bill
    Fabio FZero, Mar 15, 2007
    #3
    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. William Hudspeth
    Replies:
    1
    Views:
    394
    Sion Arrowsmith
    Mar 16, 2007
  2. Tim Golden
    Replies:
    0
    Views:
    455
    Tim Golden
    Oct 7, 2007
  3. Danny Wong (dannwong)

    subprocess.Popen and thread module

    Danny Wong (dannwong), Aug 10, 2011, in forum: Python
    Replies:
    1
    Views:
    219
    Thomas Rachel
    Aug 10, 2011
  4. Andrew
    Replies:
    3
    Views:
    148
    emile
    Nov 30, 2012
  5. Mark Lawrence

    Re: os.popen and the subprocess module

    Mark Lawrence, Nov 27, 2012, in forum: Python
    Replies:
    0
    Views:
    139
    Mark Lawrence
    Nov 27, 2012
Loading...

Share This Page