1

I have below script which have output as well as log redirection along with date and tiem written into the log and erro files. i am saving this script with .cmd extension. Manually when i try to run this script through the command prompt it runs perfectly and first write current date and time in output and error log and then start recording the logs. but when schedueled through task schedule it only writes current date and time int othe logs but not hte actual logs. Can someone please let me know how i can schedule this script in such a way it will first record the current date and time and then start recording the logs.

Echo Date:%date% Time:%time% >> error.txt
    @echo off 
    (
    Echo Date:%date% Time:%time%
            start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_EXTRACT.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_EXTRACT.CONF"
             :loop
            for /f "tokens=2 delims=: " %%a in ('tasklist ^| find "BES_EXTRACT.exe"' ) do (
                if "%ERRORLEVEL%"=="0" (
                    ping -n 10 localhost > nul 2>nul
                    goto loop
                )
            )
            start "" /wait /b "D:\ITSMaaS\BTscripts\capgemini\BESExtract\bin\BES_DATA_MAP.exe" "-f D:\ITSMaaS\BTscripts\capgemini\BESExtract\conf\BES_DATA_MAP.conf"
        ) >> Output.txt 2>> error.txt
orj
  • 53
  • 1
  • 1
  • 6
  • also when i remove the redirection from the script and pass it as argument to the script in scheduler , log files records the logs but not the date and time. – orj Aug 22 '14 at 15:14
  • Did you see my recent answer to your last question on this topic? http://stackoverflow.com/questions/25381562/batch-to-check-if-the-first-script-out-of-two-has-completely-created-a-csv-file – foxidrive Aug 22 '14 at 15:40

2 Answers2

0

Use redirection on the batch file. In order to output date and time to both files, you could use this technique:

ECHO Date:%date% Time:%time%
1>&2 ECHO Date:%date% Time:%time%

The first ECHO will write to standard output which would be caught with >> Output.txt applied to the batch file. The second ECHO will write to standard error, that output would be redirected by 2 >> error.txt.

If you are worried that the values might differ slightly (by hundredth of a second, perhaps), you could first store the output string to a variable:

SET "datetime=Date:%date% Time:%time%"
ECHO %datetime%
1>&2 ECHO %datetime%
Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • @ Andriy thank you very much for your valuable suggestions . Your solution worked perfectly in my case. – orj Aug 27 '14 at 13:22
0

Set 'program/script' : 'yourfile.bat' WITHOUT PATH

Set 'Start in' the rest of path

widoz
  • 49
  • 1