Solved

Batch file error output to log file

Posted on 2013-12-05
5
1,439 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

756 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