PC Review


Reply
Thread Tools Rate Thread

Multiline FOR and %TIME%

 
 
rpresser@gmail.com
Guest
Posts: n/a
 
      29th Jun 2006
(It is very difficult to search Google on this topic, because it
ignores the % punctuation in my search. Very provoking.)

As is well known, the %TIME% variable expands to the current time:

C:\>echo %TIME%
10:36:30.71

If I use it several times in a batch file that takes a nontrivial
amount of time, the later times are indeed later:

C:\>type test1.cmd
echo %TIME%
ping google.com >nul
echo %TIME%

C:\>test1

C:\>echo 10:37:19.86
10:37:19.86

C:\>ping google.com 1>nul

C:\>echo 10:37:23.55
10:37:23.55

But in a loop, apparently %TIME% is only expanded once and then
substituted the same on each loop pass:

C:\>type test2.cmd
for %%i in (1 2 3) do echo %%i 10:38:28.91 & ping -n 2 google.com >nul

C:\>test2

C:\>for %i in (1 2 3) do echo %i 10:38:28.91 & ping -n 2 google.com
1>nul

C:\>echo 1 10:38:28.91 & ping -n 2 google.com 1>nul
1 10:38:28.91

C:\>echo 2 10:38:28.91 & ping -n 2 google.com 1>nul
2 10:38:28.91

C:\>echo 3 10:38:28.91 & ping -n 2 google.com 1>nul
3 10:38:28.91

The other traditional way to get the time, using for with delims and
TIME /T, doesn't get me the seconds, which I need. Any other way to
get the current time while in a loop?

 
Reply With Quote
 
 
 
 
foxidrive
Guest
Posts: n/a
 
      29th Jun 2006
On 29 Jun 2006 07:40:44 -0700, (E-Mail Removed) wrote:

> (It is very difficult to search Google on this topic, because it
> ignores the % punctuation in my search. Very provoking.)
>
> As is well known, the %TIME% variable expands to the current time:
>
> C:\>echo %TIME%
> 10:36:30.71
>
> If I use it several times in a batch file that takes a nontrivial
> amount of time, the later times are indeed later:
>
>
> But in a loop, apparently %TIME% is only expanded once and then
> substituted the same on each loop pass:
>
>
> The other traditional way to get the time, using for with delims and
> TIME /T, doesn't get me the seconds, which I need. Any other way to
> get the current time while in a loop?


@echo off
setlocal EnableDelayedExpansion
for %%i in (1 2 3) do echo %%i !time! & ping -n 2 google.com >nul
 
Reply With Quote
 
 
 
 
rpresser@gmail.com
Guest
Posts: n/a
 
      29th Jun 2006
foxidrive wrote:
> On 29 Jun 2006 07:40:44 -0700, (E-Mail Removed) wrote:
>
> > Any other way to
> > get the current time while in a loop?

>
> @echo off
> setlocal EnableDelayedExpansion
> for %%i in (1 2 3) do echo %%i !time! & ping -n 2 google.com >nul


Thank you! This is perfect.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto :: Multiline DataGridView :: More precisely a Multiline DataGridViewTextBoxColumn Gordian Microsoft Dot NET Framework Forms 0 13th Jul 2005 08:51 AM
Howto :: Multiline DataGridView :: More precisely a Multiline DataGridViewTextBoxColumn Gordian Microsoft Dot NET Framework Forms 0 13th Jul 2005 08:37 AM
multiline message boxes and ENTER keys..... Antonio Lopez Arredondo Microsoft ASP .NET 1 12th Nov 2004 08:42 PM
Bug in notepad and multiline edit box Xlnt Windows XP General 6 20th Jan 2004 04:04 AM
new line and carige return in multiline textbox Mats Boberg Microsoft Dot NET Compact Framework 3 15th Dec 2003 08:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:08 AM.