S
S
Sanya Hihi Haha2021-03-29 16:24:31
Python
Sanya Hihi Haha, 2021-03-29 16:24:31

How to write a bat script to run an exe compiled by pyinstaller?

Good day.

Actually the question, I wrote a piece of code, assembled it with pyinstaller, without any build flags. (pyinstaller main.py)
wrote this line for run.bat

start C:\Users\valinor\Desktop\hihi\dist\main\main.exe --dir='D:\ttt'


along the path C:\Users\valinor\Desktop\hihi\dist\main\main.exe, as you can see, the exe file itself lies, and I read the dir flag in the python code (this is the path to the files that I need to read in the python code (I read using sys.argv[1])), everything works if the batch file is next to main.exe, but if I transfer it - failed to execute main ..
There, next to main.exe, I have config.ini, a couple of text files and chromedriver

Actually, how can I start this whole thing correctly if run.bat is not next to main.exe?
There, judging by the fact that the problem occurs precisely in the fact that main.exe tries to read the necessary files from the directory where run.bat itself is launched

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wisgest, 2021-03-29
@ValarMayar

There are commands to change the working directory, cdlike pushd/ popd. In addition, the command itself startsupports the key for this /d. Might work

start /d "C:\Users\valinor\Desktop\hihi\dist\main" main.exe --dir='D:\ttt'

(Help on commands can be obtained by calling them with the key /?- "The answer is easily found by a search engine.")
If a batch file is created for the sake of a single command, then you can simply create a shortcut by specifying the working directory in its properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question