Link to home
Start Free TrialLog in
Avatar of levertm
levertmFlag for Canada

asked on

Batch file error output to log file

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.
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of levertm

ASKER

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.
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
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.
Avatar of levertm

ASKER

2 >>error.log worked great, thanks.