views:

6285

answers:

4

I realize that this could probably be done easier in any number of other scripting languages but started to do it quick in cmd and now Im curious.

Looking to start a process at an offset to the time that another process started. Lets say 5 minutes to keep it simple. Is there a way to add to the %TIME% variable?

For instance:

start /b foo.exe
at %TIME% + 5 minutes bar.exe

Thanks for any assistance

+4  A: 

I just typed set/? and discovered cmd is much better than old bat... :-)

set h=%TIME:~0,2%
set m=%TIME:~3,2%
set/a m2="m+5"
set t2=%h%:%m2%
set t2

Obviously, you can get 62 minutes, etc., I let you do the extra math... :-D

PhiLho
A: 

excellent, just what I needed.

Give PhiLho his due and accept HIS answer! Just delete this answer and post a comment on his answer.
Philibert Perusse
A: 

2 PhiLho

thanks

My bath code:

set h=%TIME:~0,2%
set m=%TIME:~3,2%
set s=%TIME:~6,2%
set time=%h%_%m%_%s%
mkdir c:\test\%time%
move c:\test\*.* c:\test\%time%
"C:\Program Files\WinRAR\RAR" a -ep c:\test\%time%\ -agDD-MM-YY_hh-mm-ss c:\test\%time%\*.* -zc:\arhiv\HEADERS.TXT
move c:\test\%time%\*.rar c:\arhiv\
rmdir c:\test\%time% /S /Q
A: 
        @echo off
        :: START USAGE  ==================================================================
        ::SET THE NICETIME 
        :: SET NICETIME=BOO
        :: CALL GetNiceTime.cmd 

        :: ECHO NICETIME IS %NICETIME%

        :: echo nice time is %NICETIME%
        :: END USAGE  ==================================================================

        echo set hhmmsss
        :: this is Regional settings dependant so tweak this according your current settings
        for /f "tokens=1-3 delims=:" %%a in ('echo %time%') do set hhmmsss=%%a%%b%%c 
        ::DEBUG ECHO hhmmsss IS %hhmmsss%
        ::DEBUG PAUSE
        echo %yyyymmdd%
            :: this is Regional settings dependant so tweak this according your current settings
        for /f "tokens=1-3 delims=." %%D in ('echo %DATE%') do set  yyyymmdd=%%F%%E%%D
        ::DEBUG ECHO yyyymmdd IS %yyyymmdd%
        ::DEBUG PAUSE


        set NICETIME=%yyyymmdd%_%hhmmsss%
        ::DEBUG echo THE NICETIME IS %NICETIME%

        ::DEBUG PAUSE
YordanGeorgiev