-1

I'm trying to use os.system() and a .format() for a program that hides Archive in Image. I don't understand , why the OUTPUT.jpg doesn't save in a current directory. Also, I have a GUI for it, it's easy enough to use. But Can't get an output file. It doesn't just create. Please, can you help?

Here is a code:

import tkinter as tk
import tkinter.filedialog as f
import os


def access(event):
    global arch
    arch = f.askopenfilename()
    txt['text'] = 'Choose a picture'
    btn_1.destroy()
    btn_2.grid(row=1, column=1)

def access2(event):
    global img
    img = f.askopenfilename()
    btn_2.destroy()
    os.system('copy {} + {} {}/OUTPUT.jpg'.format(img, arch, os.getcwd()))
    txt['text'] = 'Ready.'

root = tk.Tk()

txt = tk.Label(root, text='Choose archive')

btn_1 = tk.Button(root, text='Выбрать')
btn_2 = tk.Button(root, text='Выбрать')

txt.grid(row=0, column=1)
btn_1.grid(row=1, column=1)

btn_1.bind('<Button-1>', access)
btn_2.bind('<Button-1>', access2)

root.mainloop()
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
X22
  • 11
  • 5

1 Answers1

1

Use shutil.copyfileobj (not os dependant)

replace :

os.system('copy {} + {} {}/OUTPUT.jpg'.format(img, arch, os.getcwd()))

to :

import shutil

destination = open('{}/OUTPUT.jpg'.format(os.getcwd()),'wb')
shutil.copyfileobj(open(img, 'rb'), destination)
shutil.copyfileobj(open(arch,'rb'), destination)
destination.close()
Indent
  • 4,675
  • 1
  • 19
  • 35
  • The OP wants to concatenate an archive file to the end of a JPEG file. That works because programs that read JPEG will ignore random data after the end of the image data. – PM 2Ring Nov 09 '17 at 10:52
  • @Indent You mean,that I should do like this: after os.system(), use `copyfile(img, arch)` for my example? – X22 Nov 09 '17 at 10:57
  • You want copy both file `img` and `arch` in a same file ? – Indent Nov 09 '17 at 11:01
  • @Indent Yes, I can't get , instead what I should use `copyfile(img,arch)`. Please, can you show? – X22 Nov 09 '17 at 11:03
  • You can't copy 2 file in single one, but you can make 2 copy of a single file. (may be I don't understand something in your question) – Indent Nov 09 '17 at 11:07
  • @Indent I need something that looks like a copy command in cmd, mean about in windows: `copy /b k.jpg+ff.rar t.jpg` – X22 Nov 09 '17 at 11:12
  • @Indent using `copy` you can combine two files into one. That's the point of the question. – Peter Wood Nov 09 '17 at 11:55
  • Ok, it's now clear. But it's a non sense to copy 2 files into another one. the result can't be a jpg (just eventually an archive...) – Indent Nov 09 '17 at 13:10
  • @Indent the question is about hiding data in an image file. If you concatenate the contents of a file onto a jpg file, the jpg can still be viewed as the extra data is ignored. – Peter Wood Nov 09 '17 at 13:37