By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,768 Members | 2,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,768 IT Pros & Developers. It's quick & easy.

Problem with subprocess.call and cp

P: n/a
Hallöchen!

The following code

from subprocess import call
call(['cp', 'subdir/*.jpg', 'othersubdir/'])

yields

cp: call of stat for "subdir/*.jpg" not possible: File or directory not found

(This may not be the real error message since it's back-translated
from German.) I could use shell=True, however, what's going wrong
here?

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646
Oct 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Torsten Bronger wrote:
The following code

from subprocess import call
call(['cp', 'subdir/*.jpg', 'othersubdir/'])

yields

cp: call of stat for "subdir/*.jpg" not possible: File or directory not found

(This may not be the real error message since it's back-translated
from German.) I could use shell=True, however, what's going wrong
here?


under Unix, it's the shell that expands glob patterns. individual commands
usually don't know anything about such patterns.

so if you run the "cp" command directly, it will look for a single file named
"subdir/*.jpg". if you run it via the shell, it will get a list of matching files
from the shell.

here's a corresponding pure-python solution, btw:

import glob, shutil
for file in glob.glob("subdir/*.jpg"):
shutil.copy(file, "othersubdir")

</F>

Oct 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.