levertm
asked on
Batch file error output to log file
Hi guys,
I have a simple batch file, the command is as follows:
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
ASKER
2 >>error.log worked great, thanks.
ASKER
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.