I know that I need to escape the @cmd var to run:
declare @cmd 'xp_cmdshell ''echo Mary|Warrior > c:\test.txt'''
exec (@cmd)
because the character '|' would fail when running the command.
So, previous running I set:
set @cmd = replace(@cmd, '|', '^|')
As @cmd var could be any string (sent by users)... What other characters do I need to worry about ?
(I know a couple of them such as >, <)