Computing.Net > Forums > Programming > Batch Task Automation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Task Automation

Reply to Message Icon

Name: whale26
Date: August 24, 2009 at 01:31:06 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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 present

3. 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%
exit

The 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!



Sponsored Link
Ads by Google

Response Number 1
Name: gtaion
Date: August 24, 2009 at 06:24:23 Pacific
Reply:

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."


0

Response Number 2
Name: gtaion
Date: August 24, 2009 at 20:01:48 Pacific
Reply:

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%."


0

Response Number 3
Name: whale26
Date: August 25, 2009 at 03:30:19 Pacific
Reply:

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?


0

Response Number 4
Name: gtaion
Date: August 25, 2009 at 05:07:26 Pacific
Reply:

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"


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Task Automation

Task automation - help needed www.computing.net/answers/programming/task-automation-help-needed/11183.html

Select file and move to another pc www.computing.net/answers/programming/select-file-and-move-to-another-pc/17166.html

batch file to set in schedule task www.computing.net/answers/programming/batch-file-to-set-in-schedule-task/14751.html