Search code examples
sql-serversql-server-2005xp-cmdshell

Why do I get an error with sql cmdshell when it works in the actual shell?


I run the following:

EXEC XP_CMDSHELL 'fsutil fsinfo volumeinfo C:'

returns Error: The filename, directory name, or volume label syntax is incorrect. NULL NULL

However, hitting the D: drive works just fine. Also if I just run fsutil fsinfo volumeinfo C: from DOS prompt (e.g. regular command shell) - that works fine too.

What am I missing here?


Solution

  • I have no explanation as to why it doesn't work, but the following does work for me:

     EXEC master.dbo.xp_cmdshell 'fsutil fsinfo volumeinfo C:\' 
    

    Note the inclusion of the backslash at the end of the query.