Question

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?

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top