xp_cmdshell only sends first character of string I am trying to use xp_cmdshell to launch a python script with a list as its input but for some reason its only passing the first character of the string to command line. The result I get from the code below is "'D' is not recognized as an internal or external command, operable program or batch file.". If I add the START command before the path it just replaces 'D' with 'S'. This particular row I'm trying to test with concatenates to 241 characters so I'm not bumping up against the varchar limits for xp_cmdshell. Using MSSQL 2008R2 on Windows Server 2008R2.

DECLARE
    @inspection varchar

SELECT
    @inspection = 'D:/Python27/ArcGISx6410.1/python.exe D:/GIS-DATA/Scripts/whydrant_update_01.py [''' + COALESCE(FACILITYID, '') + ''',''' + COALESCE(MAKER, '') + ''',''' + COALESCE(HYDRCOND, '') + ''',''' + COALESCE(BASECOL, '') + ''',''' + COALESCE(CAPCOL, '') + ''',''' + COALESCE(STEAMSIZE, '') + ''',''' + COALESCE(DISSIZE, '') + ''',''' + COALESCE(CAST(FLOW AS varchar), '') + ''',''' + COALESCE(CAST(PRESSURE AS varchar), '') + ''',''' + COALESCE(VALVELOC, '') + ''',''' + COALESCE(ACTIVE, '') + ''',''' + COALESCE(OPERABLE, '') + ''',''' + COALESCE(OPERHARD, '') + ''',''' + COALESCE(CORRODED, '') + ''',''' + COALESCE(CLEARING, '') + ''',''' + COALESCE(PAINTING, '') + ''',''' + COALESCE(MARKER, '') + ''',''' + COALESCE(NOTE, '') + ''',''' + COALESCE(CAST(created_date AS varchar), '') + ''',''' + COALESCE(USER_, '') + ''']'
FROM sde.sde.a1288
WHERE FACILITYID = '2294'


EXEC xp_cmdshell @inspection
The problem is with your variable declaration varchar.

The command_string is   varchar(8000) or nvarchar(4000)

so define your variable along with proper length  to avoid string truncation


  DECLARE
      @inspection varchar


should be 


  DECLARE
      @inspection varchar(8000)


couple of things as well (since I dont know Python).


Make sure you print or select @inspection and see that you can run the produced command successfully.
Use a variable for success or failure and raise an error message when the command fails.


e.g. 

declare @result int
DECLARE @inspection varchar(8000)  
exec @result = master..xp_cmdshell @inspection 
if @result &lt;&gt; 0
begin 
    print 'Python script errored out !!'
    RAISERROR ('Python script errored out', 16, 1)
end