Computing.Net > Forums > Programming > display on-screen and output to txt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

display on-screen and output to txt

Reply to Message Icon

Name: cybpsych
Date: December 29, 2008 at 21:47:49 Pacific
OS: Windows XP
CPU/Ram: P4 2.8GHz, 2GB DDR40
Product: None / NONE
Comment:

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.txt

the 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!



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: December 30, 2008 at 00:33:48 Pacific
Reply:

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
)


0

Response Number 2
Name: reno
Date: December 30, 2008 at 04:03:06 Pacific
Reply:

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.


0

Response Number 3
Name: Judago
Date: December 30, 2008 at 05:05:45 Pacific
Reply:

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.......


0

Response Number 4
Name: reno
Date: December 30, 2008 at 05:40:58 Pacific
Reply:

anyone know why this line is not working:

if ERRORLEVEL 0 (echo YES) else echo NO


0

Response Number 5
Name: Holla
Date: December 30, 2008 at 10:46:35 Pacific
Reply:

hmmm reno,
what do u mean by not working

 0:14:59c:\holla>if ERRORLEVEL 0 (echo YES) else echo NO
YES

0:15:01c:\holla>if ERRORLEVEL 1 (echo YES) else echo NO
NO

0:15:07c:\holla>ver

Microsoft Windows [Version 6.0.6001]

0:15:17c:\holla>

--
Holla.


0

Related Posts

See More



Response Number 6
Name: Judago
Date: December 30, 2008 at 15:54:28 Pacific
Reply:

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
........


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: display on-screen and output to txt

Dos (?) www.computing.net/answers/programming/dos-/16082.html

Help a student with his C assignment.. www.computing.net/answers/programming/help-a-student-with-his-c-assignment/1783.html

Webpage content to TXT file www.computing.net/answers/programming/webpage-content-to-txt-file/14510.html