Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to create a batch file that will run an exe that will test out the readability of a CD. The process is supposed to work out as follows:
1. The PC & OS loads up, and the CD checking .exe will automatically execute
2. Another batch file will need to check whether or not this program is still executing, say, every 25 seconds - it will do this by creating a text file that lists all currently running processes and searching through the list to see if the process is present3. If the process is present, the program will loop to the beginning and wait again, and check again
4. If the process isn't present, then the PC will restart and the process will start all over again.My code is as follows:
@ECHO OFF set tempfile=process.txt wait(25) tasklist > %tempfile% tasklist /fi "readtest.exe" if errorlevel 0 if not errorlevel 1 goto IsRunning :IsRunning echo This process is running goto exit :exit del %tempfile% exitThe problem I am having is that the program is loading OK, but the text file isn't getting created, and so the checking on whether the process is still active is therefore also malfunctioning.
Any help would be hugely appreciated as I have been trying to get this to work for too long!

If you did something like this, it would bypass the need to have a text file, All you have to do is replace readtest.exe with the name of you CD checking program, then every 25 seconds it will check to see if that program is running, if not it will give the user 5 seconds before restarting, the only way to cancel the restart would be in that 5 second window the user would have to open a command prompt and type "shutdown /a" to abort the shutdown process.
echo off
:loop
tasklist | find /i "readtest.exe" >nul
if %errorlevel% EQU 0 (
echo:CD Checking service running...
ping 127.0.0.1 -n 25 >nul
goto loop
)
shutdown /r /f /t 5 /c "System rebooting to re-start CD Checking service."

Here is another way to do it, this way actually writes to a textfile that is stored in the your temp directory while it is being used. In you example above when I run it on my computer the first thing I get is an error 'cuase wait is not a valid command then it creates the textfile, then I'm not sure what you have going on with the next command.
So if you want it to run without actually creating a textfile, use the commands in response 2, if you actually need it to read from a textfile, i.e. a homework assignment, here you go,@echo off
REM Change the Process to the one you want to look for.
set process=readtest.exe:begin
tasklist > "%temp%\process.txt"
for /f "usebackq" %%a in ("%temp%\process.txt") do (
if %%a equ %process% (
echo %%a is running...
ping 127.0.0.1 -n 25 >nul
goto begin
))
del /q "%temp%\process.txt"
shutdown /r /f /t 5 /c "System rebooting to re-start %process%."

Thanks for your replies.
The code for the inclusion of the text file is giving me an error - on the command line it's saying '/f "usebackq" was unexpected at this time'
Any ideas on why this is so?

Check to make sure that all of the spacing is there, double check to make sure that there is a space between /f and "usebackq"

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |