Run exe file with parameter from SQL Server

Viewed 3387

enter image description hereI have created a console application and now I want to execute this .exe file from SQL Server. Running this query only gets null output. Please help me.

    DECLARE @CMDSQL VARCHAR(1000), 
            @Reportname VARCHAR(100),
            @TerminalCode VARCHAR(10),
            @FinYear VARCHAR(10)  

    SET @Reportname =('05 - Import Load Delivery')  
    SET @FinYear='2017-18'  
    SET @TerminalCode='BOM'  
    SET @CMDSQL = '"D:\ExportToExcel.exe" ' + @Reportname + ' ' + @TerminalCode + ' ' + @FinYear  

    --print @CMDSQL  
    Exec master..xp_cmdshell @CMDSQL
2 Answers

No answer on this post. I found that including your ENTIRE statement within double quotes works. So you end up with nested double quotes.

So in your example:

SET @CMDSQL = 'CMD /S /C " ""D:\ExportToExcel.exe"  "' + @ReportName + '" "' + @TerminalCode + '" "' + @FinYear + '" ""'

or in mine that I was trying to figure out:

EXEC xp_cmdshell '""C:\XML\ExecURL.exe" "http://devserver/app/retreiveshippinglabels/RGAGetLabels?RMA_NO=171269""';  
Related