November 27, 2015

How to organize exe and dll files - solution by Python

How to organize dlls?
We require 3 things:
1. not to mess up environment variable PATH
2. not to have 4747 dlls by each .exe file
3. not to have same dll more than once

Requirements of issue exe files:
1. run several exe files in un/specified order
2. run with arguments
3. use data from somewhere around
4. you are lazy to click and open it one by one
5. never wants to use batch file because you may need some other workaround in the future

How to do that?

Save and organize dlls to folders as you like.
We will use python2.7. Install it.

Write script which prepare everything, set temporary PATH for this process and run exe files.
Something like this:

import os

thisDir = os.getcwd()
print thisDir

dependenceList = [];
dependenceList.append("")
dependenceList.append("Boost-1.59.0")
dependenceList.append("flann")
dependenceList.append("FlyCapture")
dependenceList.append("Qt5.5.0")
dependenceList.append("libtiff")
dependenceList.append("OpenCV-3.0.0")
dependenceList.append("PCL-1.7.2")
dependenceList.append("qhull-2012.1")
dependenceList.append("VTK-6.3.0")
dependenceList.append("ximea")
dependenceList.append("zlib")

dllDirectory = thisDir + "/../dll"
path = dllDirectory

for dependence in dependenceList:
    path += ";" + dllDirectory + "/" + dependence

#because windows is looking for dlls in order
# and if somebody else provides dll with the same name, yours one comes earlier
path += ";" + os.environ["PATH"]

os.environ["PATH"] += path
print os.environ["PATH"]

PhoXiGuiExe = thisDir + "/PhoXiGui.exe"
PhoXiProjectExe = thisDir + "/PhoXiProject.exe"

print PhoXiGuiExe launching
os.system("start cmd /C " + PhoXiGuiExe)

print PhoXiProjectExe  launching
os.system("start cmd /C " + PhoXiProjectExe)

Only one thing is missing. Maybe someone with computer without python installed wants to run it. No problem. Write

pip install pyinstaller
to cmd and then
pyinstaller.exe --onefile yourPythonScript.py

Now in dist dir you will find .exe which will do everything you demand. Do not forget: path thisDir from example coincide with location resulting exe file will be finally run from.

No comments:

Post a Comment