0
for /f "tokens=1-4 delims=/-\ " %%a in ('date /t') do (
  SET mjour=%%a
  SET mmois=%%b
  SET mannee=%%c
)

SET date=%mjour%%mmois%%mannee%

echo 'hello' > "D:\db2support\dbauditarchive%date%.log" 2>&1

D:\DB2_V9\IBM\SQLLIB\BIN\db2cmd.exe "rexx D:\db2support\dbauditarchive.cmd" >  D:\db2support\dbauditarchive%date%.log 2>&1

I am running a REXX program containing DB2 commands. To run this REXX program I created the .bat file as shown above. But my output never gets written to the output(log) file. The file gets created but is blank. The REXX file contains no errors and if I run it through a cmd window the the output shows on the cmd window. Can you see what is my mistake here?

  • `date` is a reserved variablename, containing the system date, although a user-set variable *should* override it. There seems to be no reason why the file should be empty. Does the file generated by the `echo` exist and is it as expected? That should be overwritten by the `db2cmd` output since you are using `>` (the *create* redirector). What happens if the redirection is removed from the `db2cmd` line? – Magoo May 25 '17 at 05:07
  • The `echo` line works and 'hello' is printed to the output file, and yes that gets overwritten by the next line. If I remove the redirection the script runs and produces the output on-screen. – CodeHack737 May 25 '17 at 06:35
  • 1
    I think you need to make output redirection a part of the command you send to `db2cmd`: `db2cmd.exe "rexx D:\db2support\dbauditarchive.cmd > D:\your.log"` – mustaccio May 25 '17 at 11:16

0 Answers0