0

I'm trying to print from a SQL Server stored procedure to a Label printer using ZPL with variables and a network printer

I've tested the ZPL to make sure it's working and then learned how to pass it through a PowerShell script to get it to print to the correct network printer and its working but I'm stumbling trying to get the command to run in SQL server's xp_cmdshell.

DECLARE @Pickloc varchar(6) 
DECLARE @powershell varchar(2000)
print @powershell
set @Pickloc = 'PCK002'
set @powershell = 'powershell.exe  -command """"^XA ^LH0,50^FS ^PR4,4 ^LL2233 ^CI0^FT20,15^A0N,20,20^FDBACKSTOCK^FS ^CI0^FT180,30^A0N,65,65^FDPick Loc: PCK002^FS ^FO50,50^GB700,1,3^FS ^CI0^FT50,114^A0N,65,65^FDSKU: 91007419^FS ^CI0^FT50,184^A0N,65,65^FDBackstock Loc: FL0002^FS ^FO50,200^GB700,1,3^FS ^CI0^FT50,270^A0N,48,48^FDDriver: Driver^FS ^CI0^FT50,330^A0N,48,48^FDFrom Loc: ABC001^FS ^CI0^FT475,330^A0N,48,48^FDTAG: T123456^FS ^XZ""" | Out-Printer -NAME """\\PrintServer\MyPrinter"""""'

print @powershell

EXEC master..xp_cmdshell @powershell

I'm expecting the string to get passed to PowerShell and print the ZPL. I'm running into issues I think with windows cmd's escape character "^" I'd also like to pass the variable @Pickloc inside the ZPL but I can't get past this part first.

1 Answers1

0

I never got an answer but instead of injection the zpl into the powershell command via xp_cmdshell I resorted to creating a text file with the zpl with the variables then calling that file in powershell. Automatically