0

I have a little issue about logging files. I want to export this string called test, but i dont know why i cant do that.

I know that command_string should not have more than 8000 characters. I don't understand why this doesn't work. Can anyone help me with that?

DECLARE @LogFilePath varchar(max)
DECLARE @teste varchar(max) = 'columnsToSelect = [street],[locality],[postalCode1],[postalCode2],[isMainAddress]'

SET @LogFilePath = 'C:\Users\epascoal\Documents\Logs\Log_ImportToSQ.txt'

SET @cmd ='echo '+ @teste +' >>'+@LogFilePath
exec master..xp_cmdshell @cmd

This works with smaller strings.

Question:How can i write large strings into a logfile?

Thanks in advance.

ePascoal
  • 2,362
  • 6
  • 26
  • 44

1 Answers1

0

echo on command line has no 'out' parameter, and it wouldn't recognize it anyway without the parameters being properly escaped.

You can try actually redirecting it:

SET @cmd ='echo '+ @teste +' > '+@LogFilePath
exec master..xp_cmdshell @cmd

Redirecting like this is supposed to work.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • Sorry, i mean it '>>' not 'out'. The problem here is that i cant write big strings.. like @teste is. – ePascoal Dec 23 '13 at 14:32