Computing.Net > Forums > Disk Operating System > dos batch script problem

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.

dos batch script problem

Reply to Message Icon

Name: Srihari
Date: July 17, 2003 at 22:46:07 Pacific
OS: windows2000
CPU/Ram: 256MB
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 18, 2003 at 15:44:33 Pacific
Reply:

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 error

echo 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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: dos batch script problem

Dos Batch Script with Type www.computing.net/answers/dos/dos-batch-script-with-type/14148.html

DOS Batch Scripting www.computing.net/answers/dos/dos-batch-scripting/12777.html

Batch Script Problem www.computing.net/answers/dos/batch-script-problem/14686.html