0

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?

1 Answer 1

1

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

1
  • 1
    I think it should be exec('net use T: /DELETE /y 2> NUL'); since we want to redirect STDERR to null.
    – cleong
    Aug 28, 2012 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.