• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

DOS batch file question

ShrewLWD

Weaksauce
Joined
Feb 12, 2002
Messages
74
Hey guys...
How do you suppress error messages in a DOS file that runs in Win2000/XP?

This is a file to be clicked on by external reps to connect shared folders to their computer...

@ECHO OFF
REM ___Company Share Directory_____
ECHO.
ECHO.
ECHO.
ECHO --Connecting Company Share Directory--
NET USE T: \\SERVER_NAME_REMOVED\CompanyShare
If NOT errorlevel 1 GOTO next
ECHO.
ECHO *** An error occured during Connection to Company Share Directory ***
ECHO Drive not connected

REM ___Sales Directory______
:next
ECHO.
ECHO.
ECHO.
ECHO --Connecting Sales Directory--
NET USE S: \\SERVER_NAME_REMOVED\Sales
If NOT errorlevel 1 GOTO last
ECHO.
ECHO *** An error occured during Connection to Sales Directory ***
ECHO Drive not connected

REM ___Keep Window Open to View Results________
:last
ping -n 5 localhost >nul

Should the connection fail, I'd like it to say the error message I have created, not Error 53, Connection not found, or whatever.
I tried using CTTY NUL and adding >CON to all echo's, but CTTY has been removed.

Any thoughts or suggestions?
 
pipe the output of the net command to NUL

ie
NET USE T: \\SERVER_NAME_REMOVED\CompanyShare > NUL

[edit] actually that will just prevent the output from being displayed, i suppose you could pipe it to a variable and then check its value, which is no trivial task in batch [/edit]
 
sgarissta -> yeah, I tried that. It works for the ping command, but for some reason it doesn't for the NET USE command.

BTW what I'm doing to guarantee a fail is to incorrectly spell the share folder name. ie \\xxx\companyshar
 
Probably because NET uses stderr instead of stdout to write to. > only redirects stdout. AFAIK, you can't redirect stderr with the windows CLI.


nitpick : it's not DOS if you're under NT.
 
XP cmd.exe can redirect stderr just fine. I did it yesterday.
 
STL ->What's your take on how to supress a NET USE error command? Do you have a quick and dirty switch or code to hide it?
 
C:\Temp>net use \\mlar 2> NUL

C:\Temp>net use \\mlar
System error 53 has occurred.

The network path was not found.


C:\Temp>
 
STL -> I've tried every possible combination of spaces and uppercase letters with > NULL, but I still get results exactly as your example.

Did yours actually run, or are you showing an example based on your experience and knowledge?

This is a .bat file that will be clicked on while in the WinXP/2000 environment... does that change anything?
 
> I've tried every possible combination of spaces and uppercase
> letters with > NULL

NUL, one L.

> but I still get results exactly as your example.

Isn't my example... what you want?

> Did yours actually run

Yes, I typed it in by hand.

> This is a .bat file that will be clicked on while in the WinXP/2000
> environment... does that change anything?

Shouldn't matter.
 
STL -> Sorry, typed too fast...yes, I am using NUL, not null...

What I would like to have happen is;

this error message is supressed:
System error 53 has occurred.

The network path was not found.


My coded error message is shown:
*** An error occured during Connection to Company Share Directory ***
Drive not connected

At the moment, both show up, even with the >nul at the end of the NET USE command line.
 
I did, and did not realize that was part of the code, I thought it was part of the name of the share... I do apologize!!!

It does indeed work, THANKS VERY MUCH!!!

Can you get technical and explain what it is doing?
Is it an IF command...If errorlevel 2, output to Nul?
 
> It does indeed work, THANKS VERY MUCH!!!

A wootness in the sky.

> Can you get technical and explain what it is doing?
> Is it an IF command...If errorlevel 2, output to Nul?

It's redirecting the standard error stream to NUL. 0 is standard input, 1 is standard output, 2 is standard error.

Also, ameoba owes me one cookie now. Chunky, not that god damn chewy kind, you hear.
 
well since this is a dos batch file based thread I thought I'd ask a question here to keep the threads down. This may well be a very stupid and newb question but I'm not very familiar with batch files in general. I have a batch file that connects to an ftp server uploads a zip file, writes all the info to a log file and then quits (this isn't warez related at all, a client support thing actually). Is there anyway whatsover to run this file without visually opening a dos/cmd window on the user's screen?

Thanks much and forgive me if it's an obviously daft question.
thanks.
 
I have done this before but i cant remember how atm. I know it involves a very short vb script tho, i'll keep looking and see what i can find.
 
Back
Top