cómo desasignar silenciosamente unidades de red mapeadas

I have a local running PHP script in which I do this

exec('subst T: C:\\Development');

but in case T: is already mapped or subst' to some other location I want to unmap it first. so I do this

exec('net use T: /DELETE /y');
exec('subst T: /D');

but when T: is not mapped the exec net use will print an error to the console, and when it is mapped but not subst' the exec subst will print an error to the console. I want to have clean output in the console window, so no error when I try to unmap a drive that isn't mapped. the problem is I have absolutely no clue how to go about this.. can I suppress printing of the error message? if not, how do I run the commands only if the drive is mapped? then, coincidentally, how do I know if I should do net use /d or subst /d?

preguntado el 28 de agosto de 12 a las 13:08

1 Respuestas

Agrega una > NUL after each command to pipe their output into...nowhere. i.e. exec('net use T: /DELETE /y > NUL');

Respondido 28 ago 12, 13:08

Creo que debería ser exec('net use T: /DELETE /y 2> NUL'); since we want to redirect STDERR to null. - Cleong

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.