xp_cmdShell doesnt write to a text file

  • Hi,

    Any idea why when using xp_cmdshell to write to a text file (Exec master..xp_cmdShell 'ECHO this is test text >> C:\test_06152004.txt'), it doesnt write to the file at all.

    This is the case when i execute the command in MSSQL installed in win2k server.

    But this works fine in MSSQL installed in win2k and win xp.

    Also, if i execute the above in isqlw of MSSQL installed on win2k server) with a folder structure as - Exec master..xp_cmdShell 'ECHO this is test text >> C:\test\test_06152004.txt' this gives a message that system file path not found!

    But when i execute the command as - Exec master..xp_cmdShell 'ECHO this is test text >> test_06152004.txt', and then execute the command - Exec master..xp_cmdShell 'dir tes*.*' - it shows that the previous command has created the file (test_06152004.txt) in C:\WINNT\system32 - but when i navigate to the folder (C:\WINNT\system32) either in the win explorer or cmd prompt and search for the file, i cannot locate the file at all!!

    Some really strange behaviour here..

  • You are looking in the SQL Server's C:\WINNT\system32 directory, and not your own local C:\WINNT\system32, right?


    Cheers,
    - Mark

  • Gawd! I'm a dummy!

    Mark, thanks for pointing out the obvious.. I was actually looking at C:\WINNT\system32 of my machine.. the sql server is in a different box and I never even thought that the command is executing on the box where SQL server is installed!

    Sorry for wasting time folks! Now I do see that the text files are being created in the sql server.

    Thanks again Mark.

  • Glad we sorted that out before you got frustrated and tried out the "format" command.


    Cheers,
    - Mark

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply