2

I have got the following script which executes a separate step one after the other:

@echo off
set /p guid=Please enter GUID:
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test map %guid%
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test compare %guid%
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test analyse %guid%
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test update %guid%
pause 

I would like to log the output of each of these steps into its own text file preferably with a name that corresponds to the process being executed, so the following log files would be created:

map.txt
compare.txt
analyse.txt
update.txt

what would be even better is if the files had the date and time prepended to them:

2015-09-22 10:23:47.048_map.txt
2015-09-22 10:23:47.048_compare.txt
2015-09-22 10:23:47.048_analyse.txt
2015-09-22 10:23:47.048_update.txt
4

I'm going to guess that you've figured this out by now. For others who may have a similar question, here is an answer:

@echo off
set filePrefix=C:\%Date:~10,4%-%Date:~4,2%-%Date:~7,2%%time%_
set /p guid=Please enter GUID:
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test map %guid% > %filePrefix%map.txt
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test compare %guid% > %filePrefix%compare.txt
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test analyse %guid% > %filePrefix%analyse.txt
start /wait Drop\Debug\Ylp.Web.CmsImportWebJob.exe /test update %guid% > %filePrefix%update.txt
pause

Note that %date% and %time% may be formatted differently in different locales — %date% might or might not include the day of the week, and might possibly be dd/mm instead of mm/dd; %time% might be hh:mm:ss or something else (e.g., hh-mm-ss), possibly with fractional seconds (decimal point) — so this may need to be adjusted. The offsets into %date% (10, 4, & 7) may need to be adjusted to locate the year, month, and day. If %time% contains colons, you need to remove/replace them for Windows filenames, and the hour might have a leading space (instead of zero) between 1:00 and 9:59 AM.

  • 2
    Note that %date% and %time% may be formatted differently in different locales — %date% might or might not include the day of the week, and might possibly be dd/mm instead of mm/dd; %time% might be hh:mm:ss or something else (e.g., hh-mm-ss), possibly with fractional seconds (decimal point) — so this may need to be adjusted. The offsets into %date% (10, 4, & 7) may need to be adjusted to locate the year, month, and day. If %time% contains colons, you need to remove/replace them for Windows filenames, and the hour might have a leading space (instead of zero) between 1:00 and 9:59 AM. – Scott Aug 22 '15 at 11:19
  • There is much discussion in Super User question Format date and time in a Windows batch script on the locale issues, with several possible solutions. – DavidPostill Aug 22 '15 at 12:51
  • Thanks, for the extra info Scott. Forgot to mention that. – krowe Aug 22 '15 at 15:21
  • @krowe this solution does not work, it doesnt create any files! – farhad-taran Aug 23 '15 at 9:27
  • 1
    @Xerxes: (1) Is the output from the commands showing up anywhere (e.g., on the screen or in another file)?  (2) If not, are you sure that your program has output?  (If you run it with no > filename, do you get output to the screen?)  (3) And can that output be redirected?  Try running the commands with plain filenames, e.g., > map.txt, > compare.txt, etc., and verify that that works.  (4) You can get some insight into what your script is doing by commenting out the echo off command.  (5) Do you need to use start /wait?  What happens if you just run the program? – Scott Aug 23 '15 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.