0

I spend a few hours writing a little script. Basically what it does is create a new text file and fills it up with whatever. I zip the text file --using zipfile-- and here's where my problem lies.

I want to run the Windows system command:

copy /b "imgFile.jpg" + "zipFile.zip" newImage.jpg To merge the image "imgFile.jpg" and the zip "zipFile.zip".

So:

os.system("copy /b \"imgFile.jpg\" + \"zipFile.zip\" newImage.jpg")

When I run my script, it all seems to go fine. But when it's done and I try to extract the 'newImage.jpg' file, it gives me:

The archive is either in unknown format or damaged

This ONLY happens when I run the system command within the script. It works fine when I use the shell. It even works if I use a separate script.

I've double checked my zip file. Everything is in good shape. Is there something I'm doing wrong? Something I'm not seeing?

user2681562
  • 513
  • 1
  • 4
  • 5

2 Answers2

1

Have you tried using shutil?

import shutil
shutil.copy(src, dst)
Noel Evans
  • 8,113
  • 8
  • 48
  • 58
0

There may be a problem with the way Python is passing the arguments to the shell command. Try using subprocess.call. This method takes arguments as an array and passes them that way to the command:

import subprocess
subprocess.call(["copy", "/b", '"imgFile.jpg" + "zipFile.zip"', "newImage.jpg"])
disatisfieddinosaur
  • 1,502
  • 10
  • 15