3

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

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

This does run the .bat but the .exe it runs is never run.

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.

maxweber
  • 576
  • 1
  • 5
  • 12
  • 3
    @closer , your vote is immature. this is purely valid (interesting) question. – Royi Namir Nov 03 '14 at 15:50
  • From my experience it should work. run this and tell us what the result `EXEC master..xp_cmdshell 'whoami` – Royi Namir Nov 03 '14 at 15:53
  • try adding in the start of your bat " pushd "%~dp0" " and end of the file add "popd", and let us know if it fix the problem – Carlos Cocom Nov 03 '14 at 17:32
  • whoami works and givestwo rows: cpi\sqlsvc NULL – maxweber Nov 04 '14 at 15:12
  • pushd and popd didn't seem to do anything. – maxweber Nov 04 '14 at 15:14
  • this also works: exec master..xp_cmdshell 'dir *.exe' ; – maxweber Nov 04 '14 at 15:19
  • Should have thought of this before. Looks like a library issue. No error messages in SQL Server. No error message in power shell. but in Command console it works fine locally but when i Remote into the server and then when I try to run the .exe directly then a dialog pops up asking to install .net version 4.5 or something. Argh! Why can't I pack all this junk into a static lib like the olden days in windows dev... – maxweber Nov 04 '14 at 15:33
  • @maxweber please don't add answers to the question, you should make up an an own answer and accept it. Maybe someone with a similar problem might find it useful. – bummi Nov 13 '14 at 21:21

2 Answers2

0

I'm only adding this as an answer for code formatting, but try wrapping your exec in a try catch so see what the problem is...

BEGIN TRY
    exec master..xp_cmdshell '\\fs01\filefolder\runpgm.bat'
END TRY
BEGIN CATCH 
    SELECT @ERROR_MESSAGE()
END CATCH
mituw16
  • 5,126
  • 3
  • 23
  • 48
  • Thank you. Unfortunately, no exception was thrown. Now, if I do have a bad line of code in the .bat file then I do get a result row after the erroneous line like: 'REW' is not recognized as an internal or external command, – maxweber Nov 04 '14 at 15:18
0

Root cause: .Net version was not installed on SQL Server server.

Long Description:

SQL Server does not show an error. Nor does Power Shell. To debug when SQL Server silently fails using master..xp_cmdshell then you need to exit SQL Server and to debug with the [DOS] Command shell. The Command shell does cause a dialog to popup to inform the user the version of .Net is not installed. Or course, you'll need to remote into the SQL Server computer to try this out. :-)

maxweber
  • 576
  • 1
  • 5
  • 12