2

I have Windows OS (Operating System) and I am trying to install libpostal library https://github.com/openvenues/libpostal

I want to take care of everything (installations) using a .bat script and then try to run an example.

Here is a .bat script I found that tests if installation is already done else continues until finished (I think I might already have some of these parts done before):

@echo off

:: Check if MSYS2 and MinGW are installed
where msys2 2>nul >nul
if %errorlevel% equ 0 (
    echo MSYS2 is already installed. Use --force to reinstall.
) else (
    :: Install MSYS2 and MinGW
    choco install msys2
    refreshenv
)

:: Check if MSYS2 packages are updated
pacman -Qu 2>nul >nul
if %errorlevel% equ 0 (
    echo MSYS2 packages are already updated. Use --force to reinstall.
) else (
    :: Update MSYS2 packages
    pacman -Syu
)

:: Check if build dependencies are installed
pacman -Q autoconf automake curl git make libtool gcc mingw-w64-x86_64-gcc 2>nul >nul
if %errorlevel% equ 0 (
    echo Build dependencies are already installed. Use --force to reinstall.
) else (
    :: Install build dependencies
    pacman -S autoconf automake curl git make libtool gcc mingw-w64-x86_64-gcc
)

:: Check if libpostal is cloned
if exist libpostal (
    echo libpostal repository is already cloned. Use --force to reinstall.
) else (
    :: Clone libpostal repository
    git clone https://github.com/openvenues/libpostal
)

cd libpostal

:: Check if libpostal is built and installed
if exist C:/Program Files/libpostal/bin/libpostal.dll (
    echo libpostal is already built and installed. Use --force to reinstall.
) else (
    :: Build and install libpostal
    cp -rf windows/* ./
    ./bootstrap.sh
    ./configure --datadir=C:/libpostal
    make -j4
    make install
)

:: Check if libpostal is added to PATH environment variable
setx /m PATH "%PATH%;C:\Program Files\libpostal\bin" 2>nul >nul
if %errorlevel% equ 0 (
    echo libpostal is already added to PATH environment variable. Use --force to reinstall.
) else (
    :: Add libpostal to PATH environment variable
    setx PATH "%PATH%;C:\Program Files\libpostal\bin"
)

:: Test libpostal installation
libpostal "100 S Broad St, Philadelphia, PA"

pause

I save this code in a notepad file as bat_script.bat, then I left-click on .bat icon, run as administrator and get the following screenshot before the command prompt closes:

enter image description here

Can someone please help?

stats_noob
  • 5,401
  • 4
  • 27
  • 83
  • https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/pause – Junuxx Mar 31 '23 at 23:51
  • *but the command prompt/shell window always closes before I can read what happened*, enter a `pause` command in the end... – Christian Gollhardt Mar 31 '23 at 23:51
  • hey everyone... i added a pause statement and screenshot .. thanks! – stats_noob Mar 31 '23 at 23:56
  • Use `REM`, not `::` within parenthesised sequences of statements `(code blocks)` as `::` is a broken label that terminates the block. Note that `mingw` overrides the Windows version of some commands. – Magoo Apr 01 '23 at 03:58
  • Magoo: thx! So everywhere where there is :: , I should replace these :: with REM? – stats_noob Apr 01 '23 at 13:45
  • 1
    I suggest reading [debugging a batch file](https://stackoverflow.com/a/42448601/3074564) and use `if not errorlevel 1` instead of `if %errorlevel% equ 0` as described by the usage help of command __IF__ output on running `if /?` as that syntax works always. There could be used also `if errorlevel 1` and exchange true/false branches in your batch file. All external [Windows commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) in the batch file should be referenced with fully qualified file name. – Mofi Apr 01 '23 at 13:47
  • 1
    There should be used `%SystemRoot%\System32\where.exe` instead of just `where` in the batch file. `setx /m PATH "%PATH%;C:\Program Files\libpostal\bin"` is an __ABSOLUTE NO GO - NEVER EVER__. This command line __corrupts__ the __system__ environment variable `PATH` of the machine if `%SystemRoot%\System32\setx.exe` gets really write access to registry hive of local machine. `setx PATH "%PATH%;C:\Program Files\libpostal\bin"` is also a __NO GO - NEVER EVER__ as it corrupts the __user__ environment variable `PATH` in registry hive of the current user. – Mofi Apr 01 '23 at 13:50
  • 1
    Why is it necessary to add `C:\Program Files\libpostal\bin` to __system__ or __user__ environment variable `PATH`? That should not be necessary at all. A program should always run without adding a folder path to __system__ or __user__ `PATH`. The environment variable `PATH` is used by all programs installed on Windows. There should not be added a folder path to `PATH` just to get a program working at all and decrease the performance of all other programs using `PATH` variable. There are __always__ possibilities to get a program working without adding a folder path to `PATH`. – Mofi Apr 01 '23 at 13:54
  • All commands below `:: Build and install libpostal` are __Linux/Mac__ shell script commands which definitely do not work on __Windows__ *Command Processor* is processing the command lines in the batch file. I am quite sure that there is a `libpostal` documentation page which describes how to compile it on Windows on having an appropriate compiler installed at all. There is by default no C/C++ compiler installed on Windows as on Linux/Mac. – Mofi Apr 01 '23 at 13:58
  • Mofi: thank you so much for all ur help! I saw the instructions needed to install libpostal on Windows... and there are many mini-installations required .... I was hoping it might be possible to install everything at once by specifying all installations using a .bat file ... i have been trying to learn about .bat files and tried to adapt tutorials to create a .bat file for libpostal installation and then trying it on an address – stats_noob Apr 01 '23 at 14:01

0 Answers0