Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with subprocess.call and cp

Torsten Bronger
Guest
 
Posts: n/a
#1: Oct 23 '05
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

Fredrik Lundh
Guest
 
Posts: n/a
#2: Oct 23 '05

re: Problem with subprocess.call and cp


Torsten Bronger wrote:
[color=blue]
> 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?[/color]

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>



Closed Thread


Similar Python bytes