0

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
Thom A
  • 88,727
  • 11
  • 45
  • 75
Ron
  • 21
  • 6
  • 3
    Why do you want to use `xp_cmdshell` is the first place? Though you are passing a `varchar`, *not* an `nvarchar`, so any characters outside of the code page for your collation will be lost. – Thom A Jun 01 '22 at 10:58
  • `xp_cmdshell` has security implications, avoid if possible. You can just open a `cmd.exe` window and do the same. For a Agent Job, you can use a Powershell step – Charlieface Jun 01 '22 at 12:38

1 Answers1

0

Add N before

EXEC master..xp_cmdshell N'dir \\my-drive\users\myUser\utf8_folder_name\'
Ron
  • 21
  • 6