Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello !
Iam new to Dos Script.Iam struck with a problem,Plese help.
I want to execute a dos command from batch file and on error condition want to display my custom message.Say I want to copy file c:\programs\test.txt to d:\application
If the file is not present I want to display message that Installation failed.
I dont to display the System error message.I tried like this.
copy c:\programs\test.txt d:\application >nul 2>error_log
if exist error_log echo Insatallation failed
But to the surprise I find error file being created inspite of file being present and command executed successfully.
The size of error_log is 0 bytes with no message.Why is the error_log file created on successful execution/
Is there any method to check if error occured for execution of a particular dos command.
Please Help!!!!!!!!
Regards
Srihari

That issue of the system creating the file even if the output redirected to it is 0-byte is confusing, besides it depends on the operating system running.
Instead of using files to detect errors, check the errorlevel. The default errorlevel a program returns when it runs fine is 0, and it returns an errorlevel equal or greater than 1 if an error occurs. So, this would do it:
copy file1 file2 1>2> nul
if errorlevel=1 goto errorecho Installation successful.
goto end:error
echo Installation failed.
goto end:end
The statement "if errorlevel=1" will return a true value if the errorlevel is equal or greater than 1.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

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

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