Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i have some questions on displaying & output commands to text file.
Q1) assuming command:
dir/a-d/os
if i write it in batch: dir/a-d/os >> out.txt, all listings will be written to the out.txt file. BUT, it's not displayed on the screen.
So, what should i write to display on-screen AND output to out.txt file?
Q2) Assuming command:7za a -r -mx9 "abc.7z" "abc" > nul
if errorlevel=0 (echo YES) else (echo NO)i output the 7z's display to nul so that the screen output is tidy/clean.
the errorlevel=0 means success for 7za.exe. so, if success then echo Y, else echo N.
a) i tried...
if errorlevel=0 (echo YES) else (echo NO) >> out.txt
but it only show on-screen.
b) i also tried
if errorlevel=0 (echo YES) >> out.txt
else (echo NO) >> out.txtthe if output to out.txt, but the else is not processed because if-else should be in a line (correct me if i'm wrong).
For the if-else, how do i display on-screen AND output to out.txt file?
thanks guys!

To do what your asking you need a program / function called "tee". It would need to be a third party utility as it is not included in windows. The work around it to simply echo twice.
if errorlevel=0 (
echo YES
echo YES>>out.txt
) else (
echo NO
echo NO>>out.txt
)

using errorlevel:
-----------------
dir notexistfile 2>nul >nul
echo FileNotExistErrorLevel=%errorlevel%
if errorlevel=0 (echo 1.YES) else (echo 1.NO)
if %errorlevel%==0 (echo 2.YES) else (echo 2.NO)
if NOT ERRORLEVEL 1 (echo 3.YES) else (echo 3.NO)@echo off >~exist.txt
dir ~exist.txt 2>nul > nul & del~exist.txt
echo FileExistErrorLevel=%errorlevel%
if errorlevel=0 (echo 4.YES) else (echo 4.NO)
if %errorlevel%==0 (echo 5.YES) else (echo 5.NO)
if NOT ERRORLEVEL 1 (echo 6.YES) else (echo 6.NO)copy & paste this code, and you will understand.

My mistake, I normally use if not errorlevel 1 myself, and to be perfectly honest hadn't seem if errorlevel=0 used. I just copied it and didn't check properly, seems it's the same >=, geq, greater than or equal to.......

hmmm reno,
what do u mean by not working0:14:59c:\holla>if ERRORLEVEL 0 (echo YES) else echo NO
YES0:15:01c:\holla>if ERRORLEVEL 1 (echo YES) else echo NO
NO0:15:07c:\holla>ver
Microsoft Windows [Version 6.0.6001]
0:15:17c:\holla>
--
Holla.

I don't know about vista but since dos days "if errorlevel x" was always "if the errorlevel is greater than or equal to x". One is greater than zero hence the result. For this exact reason checks had to be arranged backwards.
choice /c:demo
if errorlevel 4 do this
if errorlevel 3 do this
........

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |