lundi 9 avril 2018

using for loop and windows tasklist cmd i am trying to open several programs from a batch file which are not already running

My code below doesn't work

    echo will now go ahead and load the essential programs needed for 
    project: %project%
    set "programlistopen=sublime_text.exe xampp-control.exe"                                                             
    for /f "delims=" %%j in (%programlistopen%) do ( 
    if %%j=="sublime_text"(set pathtopen=%defaultpath%\Sublime_Text&&set 
    dirpath="%workdirectory%\%project%") else
    if %%j=="xampp-control.exe"(set pathtopen=%xampp%\&&set dirpath=)
    tasklist /FI "IMAGENAME eq %%j" 2>NUL | find /I /N "%%j">NUL
    if "%ERRORLEVEL%"=="1" goto notstartedsublimetext
    if "%ERRORLEVEL%"=="0" goto startedsublimetext
    :notstartedsublimetext
    Echo started %%j at %time%
    pause
    start /d "%pathtopen%" %%j %dirpath%
    :startedsublimetext
    echo %%j is already running......
    )

Aucun commentaire:

Enregistrer un commentaire