Solved Suppress/Hide DOS System Errors

March 10, 2009 at 13:35:14
Specs: Windows XP
Thanks for anyone's help in advance!

I have created a batch file to check for a file folder, if not present to create it. Then to connect to a remote server and copy files to the local machine.

Specifically, I am requesting users enter the password for connecting to the server. There may be instances when users already have a connection to the server, and if they enter the password incorrectly I would like to suppress the system error and provide something more meaningful. Any way of suppressing system errors?

Here is my batch file:

@echo off
echo. Check if the Folder Folder already exists on this machine.

if exist "C:\Folder" (
echo. Yes! Folder Folder Exists!
pause) else (echo. Folder Folder does not exist. Create folder now.
mkdir C:\Folder
echo. Folder folder successfully created!)

echo. Connect to the server to copy the files.

echo. Checking connection to server. Please wait...
ping -n 1|find "Reply from" >NUL
if not errorlevel 1 goto:CONNECTSUCCESS
if errorlevel 1 goto:FAILURE

echo. The server cannot be reached. Contact your network admin. Hit any key to exit.

echo. Connection successful.

net use \\\Folder$ * /user:UserBob\Folder
if not %errorlevel% NEQ 0 goto:COPYFROMSERVER
if %errorlevel% NEQ 0 goto:CONFIRMERROR

if errorlevel 2 goto:RESPONSE
REM 1219 is if connection alreadty exists with credentials, and user fails to put in password
REM 1326 is if NO connection exists, and user fails to put in password

echo. You have typed the password incorrectly. Please try again by pressing any key.

echo. Now copying files...
copy "\\\Folder$\FolderApp\*.*" "C:\Folder"

echo. Done! You may now start Folder. Press any key to exit.


Thanks again for any help!


See More: Suppress/Hide DOS System Errors

Report •

March 12, 2009 at 00:36:18
✔ Best Answer
Provided this is xp or another nt based system and not dos you can redirect error messages.

Redirecting the error messages is almost the same as redirecting the standard output except you have to select the destination.

Normally to redirect standard output you would use something along the lines of:

>file.txt command

All we have to do is select the destination, there are three that are of concern:

0 - Standard input (normally keyboard but can be a file)
1 - Standard output (can be either screen or file and is implied when no handle has been selected)
2 - Standard error (default output is console)
3-9 - normally of no use, apparently "reserved" for other use.

To choose where you want the output to go simply add the number before the redirection symbol. You can supress errors like so:

2>nul command

There is also another handle of sorts "con" anything that is designated to con cannot be redirected and always will appear on screen.

Report •
Related Solutions

Ask Question