xp_cmdshell and file paths with spaces

Not sure why but xp_cmdshell has issues with spaces in file paths. For example the following 7zip command results in an error:

EXEC xp_cmdshell ‘”c:\Program Files\7-Zip\7z” a “c:\test folder\test.zip” “c:\test folder\x.bmp’

‘c:\Program’ is not recognized as an internal or external command,operable program or batch file.

One workaround to this is to ensure that the qualified path is not at the beginning of the command. For example the following will work as expected

EXEC xp_cmdshell ‘cd.. && “c:\Program Files\7-Zip\7z” a “c:\test folder\test.zip” “c:\test folder\x.bmp’

So the work around here was to insert cd.. && at the beginning of the command string.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: