Computer Hope

Microsoft => Microsoft Windows => Windows XP => Topic started by: tomlevett on December 23, 2015, 01:55:38 PM

Title: Batch file problems windows XP
Post by: tomlevett on December 23, 2015, 01:55:38 PM
Hi All,
New to this but I'm trying to set up a .bat or .cmd file to run a ping every 12 hours on a loop and record it in a file.

I've got the below running (set to every 6 seconds for trialing) successfully in windows 7 but it won't work in XP.

@ECHO on
set IPADDRESS=8.8.8.8
set INTERVAL=6
:PINGINTERVAL
ping %IPADDRESS% -n 1 >> C:\test.txt
time /T >> C:\test.txt
date /T >> C:\test.txt
timeout %INTERVAL%
GOTO PINGINTERVAL



I also tried this one
@ECHO on
cls
:start
ping 8.8.8.8 -n 1 >> d:\test.txt
echo logged time = %time% %date% >> d:\test.txt
timeout /t 6
goto start


both work fine in windows 7, but not XP.

Thanks in advance
Title: Re: Batch file problems windows XP
Post by: Geek-9pm on December 23, 2015, 03:20:38 PM
You can make it work. Some observations.
Until you get thing thing working, do not use a loo forever thing. Maybe just loop five times to see what is in the report file.

Also, the report file should be cleared the first time you use it.
Instead of a timer. maybe your should schedule the job to be done through the days.

What is this?
Code: [Select]
timeout %INTERVAL%Timeout is not found in my XP.
It is part of Windows 7/2008 and XP Resource Kit
https://technet.microsoft.com/en-us/library/cc754891.aspx
Also see:
Running Scheduled Task Multiple Times a Day (http://superuser.com/questions/382690/running-scheduled-task-multiple-times-a-day)
Title: Re: Batch file problems windows XP
Post by: DaveLembke on December 23, 2015, 03:44:44 PM
Did you install the Timeout from the resource kit and is Timeout.exe located in same location as the batch file to run?

I usually use the sleep command instead myself, but you will need to make sure you have sleep.exe if your going to use that instead.

More info here on Sleep vs Timeout http://stackoverflow.com/questions/28057443/difference-between-sleep-and-timeout
Title: Re: Batch file problems windows XP
Post by: Geek-9pm on December 23, 2015, 03:53:45 PM
DaveLembke, good catch.  :)
Title: Re: Batch file problems windows XP
Post by: DaveLembke on December 23, 2015, 04:30:51 PM
Well you knew like me that its not a normal part of XP and part of resource kit to be added for Timeout support. If that isnt installed and/or Timeout.exe not located in the directory that the batch is executed it will just return with invalid command. Hopefully this fixes it for them. If the resource kit is installed it should auto resolve for the Timeout instruction, however if they didnt install the resource kit but placed the Timeout.exe file in the same directory with the batch instruction it would probably work the same as the trick to add the Sleep command to systems that didnt come with it.  :)
Title: Re: Batch file problems windows XP
Post by: Geek-9pm on December 23, 2015, 04:49:58 PM
Also, ping can be used for a time delay, if you are using ping anyway. Still, I thunk for doing the whole day should be in Task Schedule.

Title: Re: Batch file problems windows XP
Post by: BC_Programmer on December 24, 2015, 01:08:09 AM
Also, ping can be used for a time delay, if you are using ping anyway. Still, I thunk for doing the whole day should be in Task Schedule.

I'd say for any delay more than 5 minutes or so is better approached with Task Scheduler, myself.