Reputation: 103
I have not created complex .bat files in years and my knowledge has left me.
what i need to do is have a .bat file create another .bat file that will be used to run a program with specified arguments.
for example:
.bat file creates a .bat file that contains:
myprogram.exe arg1 arg2 arg3 arg4 arg 5 "arg5" currenttimedatehour currenttimedatehour+1hour
for "arg5" - this argument must be inside "" for currenttimedatehour it needs to be in YYYY-MM-DD-HHHH format EX: 2012-02-25-1800 for currenttimedatehour+1hour it needs to be in YYYY-MM-DD-HHHH format : 2012-02-25-1900 (whatever current time is plus 1 hour)
when i try to use the simple ECHO myprogram.exe arg1 arg2 arg3 arg4 arg 5 "arg5" currenttimedatehour currenttimedatehour+1hour > myfile.bat it acts as if it is trying to run "myprogram.exe" instead of writing it to the output myfile.bat
i have not attempted the currenttimedatehour part as i have no clue how to have it look at the current date and time and format it in the format needed, much less add an hour to it?
can this be done with .bat file? if so, would anyone be so kind to share their knowledge and examples of how i can do this?
Upvotes: 0
Views: 1614
Reputation: 5620
You could have a "batch generator" like this (gen.bat) :
@echo off
set Y=%date:~10,4%
set M=%date:~4,2%
set D=%date:~7,2%
set /a H=%time:~0,2%
set /a HplusOne=%H+1
set curtime=%Y%-%M%-%D%-%H%00
set curtimePlusOne=%Y%-%M%-%D%-%HplusOne%00
echo myprogram.exe %1 %2 %3 %4 "%5" %curtime% %curtimePlusOne% > caller.bat
It gathers 5 parameters and generate a new batch file called "caller.bat", what you should ensure is if date and time format is the same as mine (maybe not.. that's the funny part to edit char positions to extract year/month/day etc.). For testing purpose, you may echo %date% and %time% to get the correct positions if it's not.
Now, let's make a tester (gentest.bat) :
@echo off
gen.bat arg1 arg2 arg3 arg4 arg5
the output in caller.bat should be
myprogram.exe arg1 arg2 arg3 arg4 "arg5" 2012-02-24-600 2012-02-24-700
I hope this help
Upvotes: 3