简体   繁体   中英

How to add the directory of a batch file to Windows PATH?

I have some Python code, developed for Linux, from a repository that I would prefer not to change. The code uses the subprocess Python module to call a command line tool named colmap .

To get this code working under Windows, I installed colmap , added the bin folder containing colmap.exe to the PATH as well as the parent folder which contains the file COLMAP.bat . I then also had to change the Python code to run colmap.bat instead of colmap via subprocess.run .
The latter step I would like to avoid, as it would make the Python code incompatible with Linux/Mac and I would like to avoid adding an OS check via platform.system() .

Is there a way to add colmap.exe to the PATH , so that it can be called via colmap by cmd.exe ?

Like I said, the bin folder is already on the PATH . I already unsuccessfully tried to create a shortcut to COLMAP.bat with the name colmap as well as renaming COLMAP.bat to colmap .

This is the content of the batch file:

set SCRIPT_PATH=%~dp0

set PATH=%SCRIPT_PATH%\lib;%PATH%
set QT_PLUGIN_PATH=%SCRIPT_PATH%\lib\plugins;%QT_PLUGIN_PATH%

set COMMAND=%1
set ARGUMENTS=
shift
:extract_argument_loop
if "%1"=="" goto after_extract_argument_loop
set ARGUMENTS=%ARGUMENTS% %1
shift
goto extract_argument_loop
:after_extract_argument_loop

if "%COMMAND%"=="" set COMMAND=gui

"%SCRIPT_PATH%\bin\colmap" %COMMAND% %ARGUMENTS%
if "%COMMAND%"=="" set COMMAND=gui

set "colmapexe="
for /f "delims=" %%b in ('where colmap.exe') do if not defined colmapexe set "colmapexe=%%b"

if defined colmapexe ("%colmapexe" %COMMAND% %ARGUMENTS%) else echo Colmap.exe not found&pause

should work by locating colmap.exe and installing it in the variable colmapexe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM