4

I'm trying to delete y: drive that mapped to a network directory using this line of batch script.

net use y: /d /y>nul

But in the situations y: doesn't exist of already deleted. it gives me this error message.

The network connection could not be found.
More help is available by typing NET HELPMSG 2250. 

Is there a way to avoid printing this error? I have tried net use y: /d /y>nul>nul but no luck

Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
  • 3
    DelboyJay answer here: [Redirect stdout and stderr to a single file](http://stackoverflow.com/questions/1420965/redirect-stdout-and-stderr-to-a-single-file) – A.J.Bauer Jul 27 '16 at 04:53

2 Answers2

8

You could not cause an error in the first place:

if exist y:\ net use y: /delete
Alex K.
  • 171,639
  • 30
  • 264
  • 288
4

You should write it like that to redirect the error to nul :

@echo off
net use y: /d /y>nul 2>&1
pause

Take a look at : I/O Redirection

Hackoo
  • 18,337
  • 3
  • 40
  • 70