Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch file error output to log file

Posted on 2013-12-05
5
Medium Priority
?
1,568 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 2000 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

715 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