rem *** OPTOPOL ***
rem *** This batch file is called from PeriData and starts the instrument control program 

rem *** create standard GDT directory - if missing
rem *** must also be defined in PTS.exe > settings, see PeriData Help pages
md C:\GDT\Optopol
rem *** copy GDT file to GDT directory
copy  C:\PeriDataExchange\Gdt2Perimeter\PERIPERI.GDT  C:\GDT\Optopol\OptoPeri.GDT
rem *** OPTIONAL - instead of the standard GDT directory for Optopol you can choose
rem *** another directory - then change these lines and 
rem *** change the definition in PTS.exe > settings

rem *** SETTINGS 
set peri="PTS"
set perilong="C:\Program Files\Optopol\PTS\PTS.exe"
if not exist %perilong% exit

rem *** START IF NOT RUNNING
rem *** 1.line TASKLIST - result is written to file (exe does not return an errorlevel)
rem *** 2.line FINDSTR - result is returned as errorlevel
rem *** 3.line set the variable NOTRUNNING (errorlevel is temporarily, lost after 1 line)
rem *** 4.line if NOT running > start "perilong"
%SystemRoot%\System32\tasklist.exe /FI "imagename eq %peri%.exe" > %USERPROFILE%\ergebnis.txt
%SystemRoot%\System32\findstr.exe /i /c:"%peri%.exe" %USERPROFILE%\ergebnis.txt 
set notrunning=%errorlevel%
if %notrunning% gtr 0 start " " %perilong%

rem *** INSTRUMENT PROGRAM WINDOW ON TOP - last command starts second batch
C:\PeriDataExchange\Gdt2Perimeter\WindowOnTop.bat %peri%

