MichaelScottPaper
asked on
Test for write access when echoing output to a text file.
Upon launch of a application batch script, the script tries to output information to a text file on a network share.
I have just found out that some users have write access and some users do not.
I want to be able to test for the person ability to write to that text file.
It appears that the echo command does not return an ERRORLEVEL status.
In unix, the IF command has tests for this type of thing.
Whats an simple and elegant way to do it in batch?
C:\>echo stuff >> no_write_perms_to_this.log
Access is denied.
C:\>echo %ERRORLEVEL%
0
C:\>
Thanks!
I have just found out that some users have write access and some users do not.
I want to be able to test for the person ability to write to that text file.
It appears that the echo command does not return an ERRORLEVEL status.
In unix, the IF command has tests for this type of thing.
Whats an simple and elegant way to do it in batch?
C:\>echo stuff >> no_write_perms_to_this.log
Access is denied.
C:\>echo %ERRORLEVEL%
0
C:\>
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thehagman, I did test this solution and it did work!
zalazar, I tested your solution and it did work as well! I do think I am going to use zalazar's solution!
Thanks both of you!
zalazar, I tested your solution and it did work as well! I do think I am going to use zalazar's solution!
Thanks both of you!
BTW personally I always write log files if possible to the temp drive, just use:
set log="%temp%\logfile.log"
and
echo whatever >> %log%
You can still launch in notepad / send by email or whatever is appropriate at the end of the script.
Steve
set log="%temp%\logfile.log"
and
echo whatever >> %log%
You can still launch in notepad / send by email or whatever is appropriate at the end of the script.
Steve
I suggest to use an external command like copy
Open in new window