Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I want to create a text file by using command shell and XP_CmdShell ESPAt command prompt (in XP) for creating a text file we can use:
C:\>copy con test.txt (ENTER)Some text (ENTER)^Z (ENTER)
I use following query:
execute xp_cmdshell 'copy con test.txt test^Z'
but this query is not correct, please post correct method/query.thanks.
robvolk
Most Valuable Yak
15732 Posts
Posted - 2009-09-11 : 17:08:00
execute xp_cmdshell 'echo test >>c:\test.txt'execute xp_cmdshell 'echo more test data >>c:\test.txt'You'll need a separate echo command for each line of text you want in the file. You cannot use the "copy con" method because it polls the keyboard.
ms65g
Constraint Violating Yak Guru
497 Posts
Posted - 2009-09-11 : 17:17:18
thank you,May post an example for creating a text file with multiple lines?
robvolk
Most Valuable Yak
15732 Posts
Posted - 2009-09-11 : 17:25:27
I did. You use the >> append operator to the same file name.