Why can I run .bat from SQL Server but not .exe?

I can run my.exe from the command line. I can run it from .bat. But, when I try to run them in SQL Server, the .exe never seems to run.

exec master..xp_cmdshell '\\fs01\filefolder\runpgm.bat'

      

This launches the .bat, but the exe file it executes never starts.

echo %date% %TIME% >> \\fs01\filefolder\test.txt
\\fs01\filefolder\CallClickSoftWS.exe >> \\fs01\filefolder\test.txt
echo %date% %TIME% >> \\fs01\filefolder\test.txt
echo "Done" >> \\fs01\filefolder\test.txt
exit

      

If I run '\ fs01 \ filefolder \ runpgm.bat' from the command line then it works fine.

+3


source to share


2 answers


I'm only adding this as an answer for formatting the code, but try wrapping yours exec

in a try catch to see what the problem is ...



BEGIN TRY
    exec master..xp_cmdshell '\\fs01\filefolder\runpgm.bat'
END TRY
BEGIN CATCH 
    SELECT @ERROR_MESSAGE()
END CATCH

      

0


source


Root Cause: The .Net version was not installed on the SQL Server.

Long description:



SQL Server is not showing error. Also not Power Shell. To debug when SQL Server silently fails using master..xp_cmdshell, you need to exit SQL Server and debug with [DOS] shell. The command shell invokes a popup dialog informing the user that the .Net version is not installed. Or, of course, you need remote access to the SQL Server computer to try this. :-)

0


source







All Articles