I am trying to use xp_cmdshell in a batch file in SQL Server 2008 Express. If I use it to execute a batch file which has the following command:
echo & gt; C: \ development \ test \ itworks.txt
A file named "itworks.txt" has been created and the text inside it is "ECO On". But if I run a batch file that has the command:
CD & Gt; Test1.txt
This does not work (no error, just nothing is made) nor does it:
Type NUL & gt; Test2.txt
Although both batch files form files, if the command prompt is double click / run I thought it might be a permissible error (I did not try echo command at that point) , Therefore changed file permissions so that NTAuthority (which runs as SQLServer service) had complete control over the folder, but it still does not work in the event log. I am a newbie in dos command, so I do not really understand the different orders. Does anyone know what is happening?
If you test commands directly at the command prompt, they work. The CD statement creates a text file that contains the name of the current directory; The
type statement generates a zero-byte file, but it actually generates a file.
Most likely, implementing
xp_cmdshell in a folder does not have any written privilege in it where it is running, and you can write the file to another location Are not specified. (
echo statement specifies a folder location for the text file, while your other two do not.)
Change your batch file to: < Pre>
CD & gt; C: \ development \ test \ test1.txt
or
type NUL & gt; If the
echo statement works when running through
xp_cmdshell , then you know that it is writable: C: \ development \ test \ test1.txt
By the NTA authorization account.
No comments:
Post a Comment