SQL and xp_cmdshell

Asked

Viewed 43 times

1

Good people, I have this little code in SQL:

DECLARE 
@StringRTF VARCHAR(MAX),
@Posh VARCHAR(8000)


SET @StringRTF = (select traduçao from artigos where Cod_Art='01010066')
select @StringRTF
SET @Posh = 'powershell.exe -ExecutionPolicy ByPass -Command Add-Type -AssemblyName System.Windows.Forms; $Rtb = New-Object -TypeName System.Windows.Forms.RichTextBox; $stringRTF = \"' + (select @StringRTF) + '\"; $Rtb.Rtf = $stringRTF; $Retorno = $Rtb.Text; Write-Host($Retorno);'
select @Posh
EXEC master.dbo.xp_cmdshell @Posh

In the select @StringRTF returns

{\rtf1 ansi ansicpg1252 deff0 deflang2070{ fonttbl{ F0 fmodern fprq6 fcharset134 Simsun;}{ F1 fnil fcharset0 MS Sans Serif;}} viewkind4 uc1 Pard lang2052 F0 fs17 'B7 'F2 'C8 'cb' B7 'Eb 'B7 'F2 'C8 'cb6346 'B8 'F6 'ba 'Ec 'B5 'C4 'B9 'F0 'bb 'A8 lang2070 F1 }

In the select @Posh returns

powershell.exe -Executionpolicy Bypass -Command Add-Type -Assemblyname System.Windows.Forms; $Rtb = New-Object -Typename System.Windows.Forms.Richtextbox; $stringRTF ="{ rtf1 ansi ansicpg1252 deff0 deflang2070{ fonttbl{ F0 fmodern fprq6 fcharset134 Simsun;}{ F1 fnil fcharset0 MS Sans Serif;}} viewkind4 uc1 Pard lang2052 F0 fs17 'B7 'F2 'C8 'cb' B7 'Eb' B7 'F2 'C8 'cb6346 'B8 'F6 'ba 'Ec' B5 'C4 'B9 'F0 'bb 'A8 lang2070 F1 par'"; $Rtb.Rtf = $stringRTF; $Return = $Rtb.Text; Write-Host($Return);

If I copy what returns in @Posh and put it on the CMD, it does what is asked

夫 人 冯 夫 人 6346 个 红 的 桂 花

but in SQL always gives me error and I’m no longer able to understand why.

The error in SQL is :

The string is Missing the Terminator: ". + Categoryinfo : Parsererror: (:) [], Parentcontainserrorrecordex ception + Fullyqualifiederrorid : Terminatorexpectedatendofstring

What could be wrong with SET @Posh?!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.