Search code examples
batch-filepm2

Batch routine avoid exit from other commands


I have a batch program that executes commands from distinct libraries. The problem is that those libraries finish console automatically when they're executed.

It seems that pause command doesn't work because probably those libraries will have they're own exit command. I tried with the command cmd /k that I found on google, but it doesn't works too.

:start
cls

echo.
echo 1) Desc 1
echo 2) Desc 2

set /p option=Enter an option: 

IF "%option%"=="1" (
    rem this is an example of library that exit console after being executed
    pm2 start ecosystem.config.js --env development
)
IF "%option%"=="2" (
    pm2 monit
)

pause

goto start

The main idea is if there's any method or param to avoid closing the console with those kind of libraries without editing the proper libraries.


Solution

  • Using the command call before the methods will work:

    :start
    cls
    
    echo.
    echo 1) Desc 1
    echo 2) Desc 2
    
    set /p option=Enter an option: 
    
    IF "%option%"=="1" (
        rem this is an example of library that exit console after being executed
        call pm2 start ecosystem.config.js --env development
    )
    IF "%option%"=="2" (
        call pm2 monit
    )
    
    pause
    
    goto start