I am running the following command:
EXEC @ReturnCode = master.dbo.xp_cmdshell @cmdline
On the Results tab I get 2 lines
Could not find a part of the path ‘\server\directory\filename’.
NULL
How do I capture the first line in an error message? I tried using a Try Catch block with “SELECT @ErrorMessage = ERROR_MESSAGE()” and it doesn’t grab it.
The message is not coming from sys.messages. Where is this error message coming from then?
The error comes from the command shell itself, it is not a SQL Server error
one way to grab the error is
but of course if you do DIR C: the table will be filled with all the files and folders from that command