Problem with subprocess.call and cp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Bronger

    #1

    Problem with subprocess.call and cp

    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

    #2
    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("subd ir/*.jpg"):
    shutil.copy(fil e, "othersubdi r")

    </F>



    Comment

    Working...