Redirection Echo Output into .txt file
Posted: 07 Feb 2010 15:17
Hi, I seem to be having some trouble with redirection, here's my code:
The output would be something like
Simply attaching ">>commlog.txt" redirects it to the file I want but there's a couple of problems with that.
It doesn't allow me to see the output on the command-line screen, which I want in conjunction with the redirected output. Also I want it to display in the text file like a log, because lets just say this program will be used multiple times I want output to be separated with a divider, I also need for the date and time to be displayed right above the output... how can I do this?
Code: Select all
@echo off
rem This is the second batch file.
cls
color 0c
if not "%5" == "" goto toomany
if "%2" == "" goto toofew
if "%3" == "" goto calc
if "%4" == "" goto calc
goto calc
:toofew
echo Too few
goto end
:toomany
echo Too many
goto end
:calc
set /a total = 0
set /a rate = 0
set /a commision = 0
if not "%5"=="" (
set /a total=%5+%4+%3+%2+%1
)else (
if not "%4"=="" (
set /a total=%4+%3+%2+%1
) else (
if not "%3"=="" (
set /a total=%3+%2+%1
set numdays=3
) else (
set /a total=%2+%1
)
)
)
if %total% leq 5000 set /a rate = 1
if %total% gtr 5000 set /a rate = 2
if %total% gtr 9999 set /a rate = 3
if %total% gtr 14999 set /a rate = 4
set /a commision = rate * total / 100
echo Total sales has been calculated as %total% >>commlog.txt
echo Commission rate has been calculated as %rate% percent >>commlog.txt
echo Total commission has been calculated as %commision% >>commlog.txt
:end
pause
The output would be something like
Total sales has been calculated as 500
Commission rate has been calculated as 1 percent
Total commission has been calculated as 5
Simply attaching ">>commlog.txt" redirects it to the file I want but there's a couple of problems with that.
It doesn't allow me to see the output on the command-line screen, which I want in conjunction with the redirected output. Also I want it to display in the text file like a log, because lets just say this program will be used multiple times I want output to be separated with a divider, I also need for the date and time to be displayed right above the output... how can I do this?