Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Batch file error output to log file

Posted on 2013-12-05
5
1,418 Views
Last Modified: 2013-12-06
Hi guys,

I have a simple batch file, the command is as follows:
for /f "tokens=*" %%i (users2.txt) do icacls.exe D:\test\%%i /grant %%i:F Administrator:F

Open in new window

It checks a file, matches names within that file to folders and adds permissions. Nice and easy. BUT, if the name is listed in the file users2.txt and there isnt a matching folder in D:\test then I get an error in cmd prompt like so, in this case BOB:
BOB: No mapping between account names and security IDs was done.
What do I need to output an error log that says something along the lines: CHECK Bob's profile path, his account isnt configured properly.
0
Comment
Question by:levertm
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 39699802
Try piping the error out to a log file:

for /f "tokens=*" %%i (users2.txt) do icacls.exe D:\test\%%i /grant %%i:F Administrator:F  2>>error.log


(all one line)
0
 

Author Comment

by:levertm
ID: 39699850
Wouldn't that pipe out the complete content output of the command? I simply want to grab the error messages, not all of output fail with the message above. Many of the results actually succeed. When I run the command something similar is output to screen...


JOHN: success
BILL: success
JOE: Success
BOB: No mapping between account names and security IDs was done.
MARY: Success
FRED: No mapping between account names and security IDs was done.
JANE: Success

I only want to output the one's where it says no mapping.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 39699891
It depends on the behavior of icalcs.exe ...
If it pipes error content to stderr instead of stdout, then it should work.  (the "2" is the key to this syntax.)  If it pipes both the success and error messages above to stdout then it won't work.  

However, if this is the case, and if you don't care about the success messages, you can still do it like this:

for /f "tokens=*" %%i (users2.txt) do icacls.exe D:\test\%%i /grant %%i:F Administrator:F  | find/v "uccess" >>error.log
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 39699896
note that I filtered out "uccess" instead of "Success" or "success" because I didn't know which of the latter two is the real output.
0
 

Author Comment

by:levertm
ID: 39701990
2 >>error.log worked great, thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question