2008-11-19 8 views
8

Ich realisiere, dass dies wahrscheinlich einfacher in einer beliebigen Anzahl von anderen Skriptsprachen getan werden konnte, aber begann es schnell in cmd und jetzt bin ich neugierig.Hinzufügen zu% TIME% Variable in Windows cmd Skript

Suchen, um einen Prozess zu einem Zeitpunkt zu starten, zu dem ein anderer Prozess gestartet wurde. Sagen wir 5 Minuten, um es einfach zu halten. Gibt es eine Möglichkeit, der Variable% TIME% hinzuzufügen?

Zum Beispiel:

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

Vielen Dank für jede Hilfe

Antwort

12

Ich tippte nur set/? und entdeckte cmd ist viel besser als alte Fledermaus ... :-)

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

Offensichtlich Sie können 62 Minuten usw. bekommen, ich lasse Sie die zusätzliche Mathematik machen ... :-D

1

2 Phi Lho

dank

Mein Bad 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 
+0

_ "Badcode" _: D – akinuri

1
 @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 
2

Hier ist die zusätzliche Mathematik:

:: Get an offset of 1 minute from the current time, accounting for edge cases 
set hr=%TIME:~0,2% 
set /a mn=%TIME:~3,2%+1 
:: check minutes; greater than 60? add n/60 to hour, n%60 to mins 
if %mn% geq 60 set /a hr=hr+mn/60 && set /a mn=mn%%60 
if %hr% geq 24 set /a h=0 
:: pad zeros if necessary 
if %mn% leq 9 set mn=0%mn% 
if %hr% leq 9 set hr=0%hr% 
+0

wenn% hr% leq 9 gesetzt hr = 0% hr: ~ 1,1% – serega386

0

copy.cmd:

set hr=%TIME:~0,2% 
if %hr% leq 9 set hr=0%hr:~1,1% 
set mydate=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%-%hr%%TIME:~3,2%%TIME:~6,2% 
copy file.txt file-%mydate%.txt 
pause