utf-8 path in master..xp_cmdshell command

192 Views Asked by At

How can I execute master..xp_cmdshell in SQL Server with path that includes utf-8 chars
the code works well in another servers and in cmd but not in sql

EXEC master..xp_cmdshell 'dir \\my-drive\users\myUser\utf8_folder_name\'

Pay attention to the path:
\\my-drive\users\myUser\utf8_folder_name\
when I call to upper folder - without utf-8 chars but same security, the command works correctly
(\\my-drive\users\myUser\ -no utf8 chars)
I also tried to wrap the path with quotation

The error is:

output
The filename, directory name, or volume label syntax is incorrect.
NULL
1

There are 1 best solutions below

0
Ron On

Add N before

EXEC master..xp_cmdshell N'dir \\my-drive\users\myUser\utf8_folder_name\'