xp_cmdshell dir different results when passing command as variable

  • I am creating a stored procedure to track some server's folders' used space using SQL Server 2008 R2. I have run into an interesting issue for a particular directory.

    When I run

    EXEC master.dbo.xp_cmdshell 'dir "\\servername\e$\media\Google" /s /-C'

    I get a different result than when I run the command using a variable for the dos string:

    DECLARE @dir VARCHAR(255) = 'dir "\\servername\e$\media\Google" /s /-C'

    EXEC master.dbo.xp_cmdshell @dir

    The number of files is the same, but the number of bytes used is different.

    Each of the files has the same size, but the total size is different.

    I have other subdirectories with zip files that do not exhibit this behavior. Does anyone have any ideas on what could cause this? Or how to fix?

    I have also posted this question to stackoverflow, with screenshots (because they are easier to upload on SO).


    [font="Tahoma"]Personal blog relating fishing to database administration:[/font]

    [font="Comic Sans MS"]https://davegugg.wordpress.com[/url]/[/font]

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply