Batch witch starts a command with parameters.

February 22, 2010 at 05:15:50
Specs: Windows Server 2003, 3.0/4 Gb.
Hi.
I need batch, which:
1) starts a command with parameters:
D:\install\trim.ovpl -u user -p pass -date %DATE%T18:00:00 -name Node
where in place of %DATE% a script must put a current date in the format of yyyy-mm-dd (for example, 02-22).
2) copies all files with expansion *.gz from the folder of D:\temp in the folder of D:\backup

See More: Batch witch starts a command with parameters.

Report •

#1
February 22, 2010 at 05:17:05
...date in the format of yyyy-mm-dd (for example, 2010-02-22).

Report •

#2
February 25, 2010 at 22:45:26
Please, help to decide this task.

Report •

#3
February 26, 2010 at 08:06:43
Well ... the date is the hardest part. What happens when you do : echo %DATE%

@echo off

D:\install\trim.ovpl -u user -p pass -date %DATE%T18:00:00 -name Node
mkdir D:\temp
xcopy *.gz D:\temp /S /D


Report •

Related Solutions

#4
February 26, 2010 at 08:36:54
not tested!

@echo off & setlocal
set xx=%~n0.bat
ren %xx% %xx%
for /f "skip=4 tokens=1" %%a in ('dir /t:a %xx%') do set dt=%%a && goto :aa
:aa
set yy=%dt:~6%
set dt=%yy%-%dt:~0,5%
D:\install\trim.ovpl -u user -p pass -date %dt%T18:00:00 -name Node
if not exist d:\backup\ md d:\backup
copy /y d:\temp\*.gz d:\backup


Report •

#5
February 26, 2010 at 09:10:30
Nbrane, how do you analyze the date when you dont know what format he is using ?

Why do you take Access time off the DIR command ?


Report •

#6
February 26, 2010 at 09:45:33
that's my attempt to get a "standard format" date, by using filedate instead of system date. I used "ren" to set the last access date of the batchfile to the current date, that way i can (maybe) be sure it is in format of mm-dd-yyyy. kind of another workaround on the whole happy-crappy date crap.

Report •

#7
February 26, 2010 at 10:19:27
You guys really need to quit flogging these DATE substrings. That will surely fail more often than not.


=====================================
Helping others achieve escape felicity

M2


Report •

#8
February 26, 2010 at 11:12:35
i know. i wish the whole issue would just evaporate. (along with the spaces-in-filenames crappola)

Report •

#9
February 26, 2010 at 13:45:33
> that's my attempt to get a "standard format"
> date, by using filedate instead of system date.
>

Nbrane, where is the coffee ... quick !


Report •

#10
February 26, 2010 at 13:47:34
> You guys really need to quit flogging these
> DATE substrings. That will surely fail more
> often than not.
>

I love a good challenge, but I'm sure somebody will have written a conversion script, which works on ALL versions of XP, whatever the set format for both time and date, and whatever the language. Really, the solution should come from MS, but ... <fill in yourself>


Report •

#11
February 26, 2010 at 17:20:12
@Tvc: Lol! yeah, coffee!
M2 et al. have already cooked one up, but you have to use debug to make it work. (it uses %errorlevel% to deliver the day, month year and day-of-week values)
Time is generally well-behaved, other than having to adjust for the local timezone. At least it's always hh:mm:ss and sometimes (no pun intended) tenths.

Report •

#12
February 26, 2010 at 17:27:02
What about this to get an independent format:

@echo off
for /f "skip=4 tokens=2*" %%a in ('
    reg query "HKEY_CURRENT_USER\Control Panel\International" /v "sshortdate"
') do set oldformat=%%b
>nul reg add "HKEY_CURRENT_USER\Control Panel\International" /v "sShortDate" /d "yyyy MM dd MMM ddd" /f
set rdate=%date%
>nul reg add "HKEY_CURRENT_USER\Control Panel\International" /v "sShortDate" /d "%oldformat%" /f
echo %rdate%
pause

It uses xp and up format reg so win2k people are probably
still out of luck.....


Report •

#13
February 26, 2010 at 19:27:05
Hi Judago, glad to see you're still with us!
regedit can be used on older systems i think, but you have to do some manipulations to make it work.
(regedit will run as non-gui if invoked from debug - it then thinks it's in dos, so then regedit /e and regedit importfile will work)

Report •

#14
February 26, 2010 at 20:41:18
Hi nbrane,

Yeah it looks like I'm still here, things have fallen
through again :(. Getting a little tired of that happening.....

As for regedit, I will leave that for someone else to screw
around with.

To answer the OP:

@echo off
for /f "skip=4 tokens=2*" %%a in ('
    reg query "HKEY_CURRENT_USER\Control Panel\International" /v "sshortdate"
') do set oldformat=%%b
>nul reg add "HKEY_CURRENT_USER\Control Panel\International" /v "sShortDate" /d "yyyy-MM-dd" /f
set rdate=%date%
>nul reg add "HKEY_CURRENT_USER\Control Panel\International" /v "sShortDate" /d "%oldformat%" /f

D:\install\trim.ovpl -u user -p pass -date %rDATE%T18:00:00 -name Node
copy D:\temp\*.gz D:\backup


Report •

#15
February 27, 2010 at 01:41:00
The debug solution I've posted many times uses BIOS and works even in DOS.

It didn't originate with me. I think it came from dtech10. Whoever wrote it can jump in here and take credit.

I haven't worked the TIME issue. It's way down the things to do list. :)


=====================================
Helping others achieve escape felicity

M2


Report •

#16
February 27, 2010 at 04:25:03
Nice command Judago ... it's not the full solution, but getting to know the current format, is not bad either.

C:\>reg query "HKEY_CURRENT_USER\Control Panel\International" /v "sshortdate"

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Control Panel\International
sshortdate REG_SZ dd/MM/yyyy


C:\>


Windows 2000 -> Windows 2003, Windows 2008 ?


Report •

#17
February 27, 2010 at 05:27:34
@tvc, Getting to know the format can be more deceptive than it looks.

All of the below is based on xp home, I have no other systems to test:

1. Some formats unexpectedly output the day of the week, like "d/MM/yyyy".

2. It's not unlikely to have the month output as a string instead of a number(ie. MMM, feb).

3. The day and month elements become strings if they are repeated more than two times (i.e MMMM). The strings still always seem to have three characters regardless(in english at least). So you can't count on elements being repeated only one, two or three times.

4. 1,2 and 3 may deal with localized strings under different languages. So you may not be able to assume jan=1, feb=2, ect. I haven't tested this personally.

5. It's possible that the format is completely useless(i.e d/d/d, ddd/MM/yy).

6. It's possible for other static text to be present in the output.

7. Ambiguous two digit years may be part of the format.

I know the command above isn't perfect but it seems to me to have the best chance without using an outside utility. There is of course a possibility that writing to the registry is out of the question, causing it to fail outright...

Also the trick *may* work in win2k ported to the version of reg it uses(I believe it's on the cd but not installed by default??). It really depends if the reg buildup changes over windows versions. I think there is a really good chance to work as is on nt 5.2, 6 and 6.1, but who knows....

Quite a while ago I wrote a script to try and parse out the date using the format, with a measure of success....


Report •

#18
February 28, 2010 at 04:07:17
Thanks Judago, interesting info and script.

A totally different method, is to use a programming language which is capable of showing the current date in a given format. I know one that does, but you have to install a database along with it. But, I'm going to have a check in C as well. The command line script you mention, looks good, but any solution for this issue should be one that works on ALL machines, except for exotic and/or de-supported platforms (Windows in Arabic or Chinese, or any Windows pre-2000)


Report •

#19
February 28, 2010 at 04:53:34
Checked the script, but I'm not sure how it goes in the end, the result is delivered via errorlevel ? (see also on that site, if it worked, you can see reply there)

Anyway, launched my old C-compiler, got this running:

D:\Temp>getdt.exe
dt_year=2010
dt_day=28
dt_month=2
dt_hour=13
dt_minutes=51
dt_secunds=27
dt_hundreds=06
dt_weekday=Sun

D:\Temp>

And the code:

#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
struct date d;
struct time t;
struct tm tm;
char str[80];

getdate(&d);
gettime(&t);
strcpy(str, asctime(&t));
str[3]='\0';

printf("dt_year=%d\n", d.da_year);
printf("dt_day=%d\n", d.da_day);
printf("dt_month=%d\n", d.da_mon);
printf("dt_hour=%02d\n",t.ti_hour);
printf("dt_minutes=%02d\n",t.ti_min);
printf("dt_secunds=%02d\n",t.ti_sec);
printf("dt_hundreds=%02d\n",t.ti_hund);
printf("dt_weekday=%s\n",str);
return 0;
}


Report •

#20
February 28, 2010 at 05:11:05
If your going to use another language vbs would be sufficient:

(sorry for my lack of vbs knowelege)

@ECHO OFF
> $$$date$$$.vbs echo Wscript.Echo Year(Now()) ^& " " ^& Month(Now()) ^& " " ^& Day(Now())
for /f "tokens=1-3" %%a in ('cscript //nologo $$$date$$$.vbs') do (
    echo year=%%a
    echo month=%%b
    echo day=%%c
)
del $$$date$$$.vbs
pause


Oh and the whole idea of leaving an errorlevel was to uses
consistent substrings on %errorlevel%. I can't see the reply
you made at pastebin, they don't cross link replies or use
consistent urls...

Edit:

I just realized that you were trying to make something
that works on dos and up. I'm not sure how it would go
on x64 if compiled for dos....


Report •

#21
February 28, 2010 at 06:18:37
Hmmyeah, something that works on as much systems as possible. 64-bit would be nice, cannot test that here. VBS is an option as well, of course, but nothing as nice as a compiled binary ... cannot mess with that anymore. Anyway, I'm having "weekday" as a string, and that is a weak point, would prefer a number there as well (to be uniform).

Sorry for the thread hijack


Report •

#22
March 1, 2010 at 00:42:36
I changed the regional settings, now:
echo %DATE% = 2010-03-01
thank you.

Report •

Ask Question