One big issue with xp_cmdshell command to create text file

  • I am using foolowing command to create text file:

    Declare @filecontents varchar(150)

    Declare @strcmdshell varchar(150)

    set @filecontents = ' '

    set @strcmdshell = 'echo '+@filecontents+' > c:\testting.txt '

    exec master..xp_cmdshell @strcmdshell

    when i run above command in query anlyzer

    i got error: "> was unexpected at this time."

    I want in text file.

    can u solve this issue, how can i create file? any way?

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • You have to use a doube >> to pipe the results to a file at the command prompt.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • What version of SQL Server are you on currently? If you are on SQL 2005, a CLR procedure with EXTERNAL ACCESS would be a much more secure method of doing this process.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • Sorry @filecontent is not displayed, bec it contains open tag ' '

    so, can u tell me, how can i write ' ' in file ?

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • What do you want it to contain specifically?

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • I use something like

    [font="Courier New"]'type filename.txt > a.txt'[/font]

    ** NOT ** [font="Courier New"]'type filename.txt' > a.txt [/font] as in "greater than"

Viewing 6 posts - 1 through 5 (of 5 total)

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