Search code examples
pythonwindowsbatch-filepython-poetry

Windows bat script fails with command on multiple line


I have two machines that need to run a single script as follows:

cd C:\my_project\
git pull
set ENV=prod
set USERNAME=me
poetry config virtualenvs.create false
poetry install
poetry run python -m my_module

Here are the version of both machines:

Machine 1

>cmd /version
Microsoft Windows [version 10.0.19042.1348]
(c) Microsoft Corporation. Tous droits réservés.

Machine 2

>cmd /version
Microsoft Windows [version 10.0.19042.1288]
(c) Microsoft Corporation. Tous droits réservés.

The script runs well on Machine 2, but stop after the first command of poetry on Machine 1. I have to modify the script on Machine 1 to have all the poetry commands in a single line separated with & to have the script which runs correctly.

cd C:\my_project\
git pull
set ENV=prod
set USERNAME=me
poetry config virtualenvs.create false & poetry install & poetry run python -m my_module

More context:

  • errorlevel is 0 after each command
  • I run on both Machines with the same user with the same privileges
  • I've restarted Machine 1 and the behavior is still the same

Is this a Windows version problem? Is this a problem with some resources (memory, CPU...)? Is this a problem with encoded/invisible characters? Installation problems with poetry?


Solution

  • On your machine1 - poetry is a batch file!
    You could use call poetry instead.

    Probably you installed poetry differently.

    This is a bug in the get-poetry.py install script, it creates poetry.bat on Windows, so the closest shell is always cmd.exe.

    Workaround is to install Poetry using pip or pipx.

    On windows poetry shell always start a cmd