Discussion:
Suppressing Error Alerts [net user /del]
(too old to reply)
Pegasus (MVP)
2003-09-07 11:09:04 UTC
Permalink
Try

net user xxx /del 2>nul

This directs all error output to nul.
Follow Up To: alt.msdos.batch.nt
I need to suppress the error message that appears when trying to remove
a user that doesn't exist on a Windows 2000/XP machine. Using the
net user xxx /delete
or
net user xxx /del
The user name could not be found.
More help is available by typing NET HELPMSG 2221.
net user xxx /del > nul
That works for when it's a success but not when I get the error. Any
ideas? Thanks.
Dazior
2003-09-07 12:11:29 UTC
Permalink
Post by Pegasus (MVP)
Try
net user xxx /del 2>nul
This directs all error output to nul.
That worked great, thanks for the prompt response. How does that work?
Where does the 2 come from, also I used:

net user xxx /del 2>nul
not
net user xxx /del 2>nul

Will it make a difference? Thanks again.
Pegasus (MVP)
2003-09-07 12:28:48 UTC
Permalink
Post by Dazior
Post by Pegasus (MVP)
Try
net user xxx /del 2>nul
This directs all error output to nul.
That worked great, thanks for the prompt response. How does that work?
net user xxx /del 2>nul
not
net user xxx /del 2>nul
Will it make a difference? Thanks again.
WinNT & up provides two types of output from command
line commands:

- Standard output
- Error output

Standard output is the default, and the following two lines
are equivalent:

xcopy . . . . >nul
xcopy . . . . 1>nul

Error output is captured with a "2":

xcopy . . . 2>nul

Note that many network commands have their "help" screen
directed to "error" output, for unexplained reasons. If you wish
to capture the help screen for route.exe then you cannot
code like so:

route /? > route.txt

but so:

route /? 2> route.txt

Your two examples for

net user xxx /del 2>nul

appear to be the same, other than for an extra space.
Please clarify your question.
Dazior
2003-09-07 13:27:49 UTC
Permalink
Post by Pegasus (MVP)
WinNT & up provides two types of output from command
- Standard output
- Error output
That was my suspicion but I wasn't certain, thanks for the
clarification.
Post by Pegasus (MVP)
Your two examples for
net user xxx /del 2>nul
appear to be the same, other than for an extra space.
Please clarify your question.
That's right, your example included 2 spaces and I wasn't sure if 2
spaces were necessary of it was a typo on your behalf. Just not sure
what the correct syntax was or if it didn't matter about the extra
space.
Pegasus (MVP)
2003-09-07 13:59:49 UTC
Permalink
Post by Dazior
Post by Pegasus (MVP)
WinNT & up provides two types of output from command
- Standard output
- Error output
That was my suspicion but I wasn't certain, thanks for the
clarification.
Post by Pegasus (MVP)
Your two examples for
net user xxx /del 2>nul
appear to be the same, other than for an extra space.
Please clarify your question.
That's right, your example included 2 spaces and I wasn't sure if 2
spaces were necessary of it was a typo on your behalf. Just not sure
what the correct syntax was or if it didn't matter about the extra
space.
In most cases (but not in all!) you can have as many
spaces between the various keywords in batch files as
you like.
Dazior
2003-09-07 14:04:53 UTC
Permalink
Post by Pegasus (MVP)
In most cases (but not in all!) you can have as many
spaces between the various keywords in batch files as
you like.
Thanks, never knew that. My batch file is coming along nicely now.
Cheers.
Dazior
2003-09-07 12:26:04 UTC
Permalink
Post by Pegasus (MVP)
Try
net user xxx /del 2>nul
This directs all error output to nul.
Strangely enough, now when the delete is successful it gives me the
success message - I also want to suppress that message. This is what i'm
trying to do:

Please enter a user to delete: bob
You have opted to delete user bob
The command completed successfully.
Successfully deleted bob.

Do you want to delete another user? [Y,N]?


---------- BEGIN CODE ----------

SET /P deluser=Please enter a user to delete:
ECHO You have opted to delete user %deluser%
ECHO Attempting to delete user %deluser% >> dellogc.txt
net user %deluser% /del 2>nul
IF %ERRORLEVEL%==0 ECHO Delete User %deluser% = SUCCESS >>
dellogc.txt & ECHO Successfully deleted %deluser%.
IF %ERRORLEVEL%==2 ECHO Delete User %deluser% = FAILURE >>
dellogc.txt & ECHO Failed to delete %deluser%.
ECHO.
CHOICE Do you want to delete another user? /C:YN
IF %ERRORLEVEL%==2 GOTO START
IF %ERRORLEVEL%==1 GOTO DELUSER

---------- END CODE ----------

Thanks.
Pegasus (MVP)
2003-09-07 13:05:41 UTC
Permalink
Post by Dazior
Post by Pegasus (MVP)
Try
net user xxx /del 2>nul
This directs all error output to nul.
Strangely enough, now when the delete is successful it gives me the
success message - I also want to suppress that message. This is what i'm
Please enter a user to delete: bob
You have opted to delete user bob
The command completed successfully.
Successfully deleted bob.
Do you want to delete another user? [Y,N]?
---------- BEGIN CODE ----------
ECHO You have opted to delete user %deluser%
ECHO Attempting to delete user %deluser% >> dellogc.txt
net user %deluser% /del 2>nul
IF %ERRORLEVEL%==0 ECHO Delete User %deluser% = SUCCESS >>
dellogc.txt & ECHO Successfully deleted %deluser%.
IF %ERRORLEVEL%==2 ECHO Delete User %deluser% = FAILURE >>
dellogc.txt & ECHO Failed to delete %deluser%.
ECHO.
CHOICE Do you want to delete another user? /C:YN
IF %ERRORLEVEL%==2 GOTO START
IF %ERRORLEVEL%==1 GOTO DELUSER
---------- END CODE ----------
Thanks.
net user %deluser% /del 1>nul 2>nul
Dazior
2003-09-07 13:32:19 UTC
Permalink
Post by Pegasus (MVP)
net user %deluser% /del 1>nul 2>nul
Thanks, I could probably worked that out if I thought about it for long
enough. Cheers!
Mark V
2003-09-07 15:40:01 UTC
Permalink
Post by Dazior
Post by Pegasus (MVP)
net user %deluser% /del 1>nul 2>nul
Thanks, I could probably worked that out if I thought about it for
long enough. Cheers!
And try this one for the experience
command >file 2>&1
Dazior
2003-09-11 05:39:24 UTC
Permalink
Post by Mark V
And try this one for the experience
command >file 2>&1
So what does this do, it appears that it puts all output into the file.
How does the &1 work? Could you explain what's happening. Thanks.
Al Dunbar
2003-09-12 00:10:12 UTC
Permalink
Post by Dazior
Post by Mark V
And try this one for the experience
command >file 2>&1
So what does this do, it appears that it puts all output into the file.
How does the &1 work? Could you explain what's happening. Thanks.
As I understand it the "2>&1" means: "oh, and direct stderr to the same
output stream as stdout. I expect that some such shorthand was required to
avoid opening two handles on the same file.

/Al
Dazior
2003-09-12 00:30:50 UTC
Permalink
Post by Al Dunbar
As I understand it the "2>&1" means: "oh, and direct stderr to the same
output stream as stdout. I expect that some such shorthand was required to
avoid opening two handles on the same file.
That was what I was thinking, it was just the & that threw me off, but
it makes sense, cause if it wasn't there then it would just redirect to
a file called 1. Cheers.

guard
2003-09-08 20:00:40 UTC
Permalink
The FREE Advanced NT/2K/XP Command Library (ntlib.cmd) provides the
RedirRapids Series of MountCommands, which are easier to remember than "1>",
"2>", etc. (especially if you don't use these every day). For example:

net user xxx /del %.Quiet%

{this will suppress normal messages but show errors}

net user xxx /del %.Kity%

{Kity=Keep It To Yourself - this will suppress errors but display normal
output}

net user xxx /del %.Silent%

(this will suppress all output}

See (http://TheSystemGuard.com/MtCmds/RedirRapids)

*******

Mount/\Commands are self-documenting and GREATLY assist in writing
maintainable scripts. The FREE Library referenced above provides over 50 of
them as an introduction to the complete set.

More info about the complete set is at (http://MountCommands.com).

*******

Notes:

1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. The (FREE) Advanced NT/2K/XP Command Library (ntlib.cmd)
provides over 50 sample Mount/\Commands to assist with
writing and documenting cross-platform scripts.
You can obtain it (for FREE) at (http://ntlib.com).

*******

-tsg
____________________________________________________________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!
Dazior
2003-09-11 05:35:54 UTC
Permalink
Post by guard
The FREE Advanced NT/2K/XP Command Library (ntlib.cmd) provides the
RedirRapids Series of MountCommands, which are easier to remember than "1>",
Thanks for the information, something i'll keep in mind for my personal
use. In this current circumstance it's not a probable option. cheers.
Loading...