How to merge two binary files into one in python and make them both execute.
For example

1.exe+2.exe = OutPut3.exe  when you run 3.exe both 1 and 2 execute

    def Main():
        File_1 = raw_input("Location path of 1.exe:")

        File_2 = raw_input(" Location path of 2.exe:")
3 Years
Discussion Span
Last Post by tony75

In python, one can execute a program using the subprocess module. For example, you can use this snippet to get program output, error messages and exit status.

With this, you can easily build a program third.py which executes the two initial binaries. Then you could use py2exe to get a third.exe.


You are not showing enough code, such as how you would create the third file "OutPut3.exe". In addition, even if you did that, the system would probably not be happy as your "executable" would contain two main() functions and it would probably just execute the first found, if it didn't give you a runtime error.

Edited by rubberman


Thanks for Asnwers
My code not work therfore I'm not showed it.

# Import needed modules
from os import system, remove
from shutil import rmtree, move

def Main():
     File_1 = raw_input("Location path of 1.exe:")
     File_2 = raw_input(" Location path of 2.exe:")
     ouput3 = raw_input(" Location path of New File Name: ")

    # Read the two files
    rf_1 = open(File_1, 'rb').read()
    encodeFile_1 = rf_1.encode("hex")

    rf_2 = open(File_2, 'rb').read()
    encodeFile_2 = rf_2.encode("hex")

    # Making a new script
    binder_script = open(ouput3+'.py','a')
    binder_script.write('''# Import needed modules
from subprocess import Popen, PIPE
from win32gui import ShowWindow
from win32console import GetConsoleWindow

Edited by tony75


You can not open 2 exe in binary mode,and try to merge these into 1 file.
exe are standalone programs,that has to be open separately.

Here a demo of what i mean,with subprocess and threads to open 2 files.

import subprocess
import threading

def file_1():

def file_2():

f1 = threading.Thread(target=file_1)
f2 = threading.Thread(target=file_2)

So this open both notepad and explorer at once.
Then i can make a exe,to open these 2 files.
So here a make 2_exe_start.exe,that's open notepad and explorer.

from distutils.core import setup
import py2exe
import sys

def py2_exe(file_in, ico):
    dest_ico = ico.split('.')[0]
    if len(sys.argv) == 1:

    # Py2exe finds most module,here you can include,exclude moduls
    includes = []
    excludes = []
    packages = []
    dll_excludes = []

    # Bundle_files : 3 most stable | bundle_files : 1 create 1 big exe
    setup(options =\
    {'py2exe': {'compressed': 1,
                'optimize': 2,
                'ascii': 0,
                'bundle_files': 1,
                'includes': includes,
                'excludes': excludes,
                'packages': packages,
                'dll_excludes': dll_excludes,}},
                 zipfile = None,

    # Can use console(Command line) or windows(GUI)
    console = [{
              'script': file_in,
              #--| Uncomment for ico
              #'icon_resources' : [(1, ico)],
              #'dest_base' : dest_ico

if __name__ == '__main__':
    #--| The .py file you want to make exe of
    file_in = '2_exe_start.py'
    #--| Ico in same folder as .py
    ico = 'your.ico'
    py2_exe(file_in, ico)

Edited by snippsat


Thanks snippsat
Is it possible we have both code in the one?For future GUI.

Edited by tony75


Is it possible we have both code in the one?For future GUI.

That should not be a problem,if i understand you right.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.