Solved

Batch file error output to log file

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now