Using wildcards with Popen in the Subprocess module

W

William Hudspeth

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
 
K

kyosohma

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
 
F

Fabio FZero

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top