Search code examples
windowsbatch-filecasperjs

Running casperjs with cmd multi-window


I read some questions about this topic but I couldnt find the solution.

This is my batch file simplified :

:MENU
CLS
ECHO.
ECHO ...............................................
ECHO Mes y a¤o elegidos: %D%/%Y%
ECHO Listado de locales 
ECHO Seleccione local para generar informe mensual
ECHO ...............................................
ECHO.
ECHO [1][COD-3003] CORNER LIDER LOS ANDES           
ECHO [2][COD-1003] CORNER MALL QUILPUE 2° PISO      
ECHO [3] 2 and 3            

SET /P M=Digita el numero del local o codigo, digita 0 para incluir todos: 
ECHO.
IF %M%==1 GOTO LOCAL1
IF %M%==2 GOTO LOCAL2
IF %M%==3 GOTO ALL

:LOCAL2
CLS
start /D "C:\n1k0-casperjs-4f105a9\sigo" cmd /k "casperjs test_optimizando_velocidad3.js 157 %D% %Y%"
GOTO MENU

:ALL
CLS
start /D "C:\n1k0-casperjs-4f105a9\sigo" cmd /k "casperjs test_optimizando_velocidad3.js 123 %D% %Y%"
CLS
start /D "C:\n1k0-casperjs-4f105a9\sigo" cmd /k "casperjs test_optimizando_velocidad3.js 157 %D% %Y%"

(forget about routes, I just copied and pasted pieces of the original file)

This approach accomplishes what a I need. Everytime I select an option opens a new window with the script running but does not close when it finishes, so when I choose all (i have like 20 options) opens 20 windows and then when script finishes shows prompt on each one instead of closing.

I tried with casperjs exit option but it didn't work , all other questions are related to open the script in the same window, I dont really know how to manage it when using new windows.

Thanks and sorry about my english, it is not my native language


Solution

  • Use cmd /c instead of cmd /k in your start commands.

    From cmd /?

    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    

    The window is staying open because the cmd process is not exiting after the command completes.