-6

When I try to run this:

exec master..xp_cmdshell 'C:\f\alert.bat'

I get the following error message:

'C:\f\alert.bat' is not recognized as an internal or external command,
operable program or batch file.

How can I run this batch file using xp_cmdshell?

EDIT: The command above is verbatim. I am not using any parameter that has spaces in it.

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120
  • 2
    Possible duplicate http://stackoverflow.com/questions/3759331/escaping-command-parameters-passed-to-xp-cmdshell-to-dtexec – billinkc May 23 '13 at 21:31
  • @billinkc From what I can see the answer to that question says to use the DOS 8.3 naming convention which, as you can see, I am already doing. I see that two people have upvoted your comment though which leads me to believe maybe I'm missing something really obvious. If so, could you point it out to me please? – Brandon Moore May 24 '13 at 17:01
  • 2
    My assumption, prior to your edit, was that `C:\f\alert.bat` was a stub for the actual command. I could reproduce your error message if I had whitespace in my xp_cmdshell call. See for yourself `exec master..xp_cmdshell 'C:\f \alert.bat'` I can change the C:\f c:\DoesNotExist and as long as there is whitespace, the "not recognized" error message is returned. The resolution to that is either use 8.3 naming convention or double quotes---both of which are demonstrated in the referenced question. – billinkc May 24 '13 at 19:20
  • @billinkc Ok, thanks. I was kinda hoping it might actually be a duplicate and that I was just missing something... guess it's not though. I just tried it as 'C:\alert.bat' too and that even produced the same error. You have any other ideas? – Brandon Moore May 25 '13 at 21:49

1 Answers1

-4

I have several servers running, and I was trying to run this command from a remote server instead of a local one. So I was getting this error because the batch file was obviously not present on the remote server.

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120
  • 2
    To bad you did not post the actual error message you got. `'C:\f\alert.bat' is not recognized as an internal or external command, operable program or batch file.` I actually did some tests to figure out what you saw but I could not recreate the error you posted with the command you posted. – Mikael Eriksson May 27 '13 at 17:10
  • @MikaelEriksson Sometimes if I'm having to access SO from a computer other than the one I'm having the error on I'll, obviously, type the error message instead of copy/pasting it. The only difference is that the real message says 'C:\f\alert.bat' instead of just 'alert.bat'. I'm inclined to wonder if this truly threw you off, or whether you are just trying to knit pick at my question. – Brandon Moore May 27 '13 at 18:55
  • Why would you think that? Do we have a history where I have answered or commented another of your questions where I offended you? I know I can be a bit direct sometimes so if that is the case I truly apologize. – Mikael Eriksson May 27 '13 at 19:04
  • 2
    And to answer your question. Yes it made me not answer your question. I guessed at that SQL server actually found the file but that you called another alert.bat from this one and that was not found. Could possibly be something with working directory. Now we know it was a lot simpler. – Mikael Eriksson May 27 '13 at 19:06
  • @MikaelEriksson This question was closed (and then reopened) and has 5 downvotes. Regardless of whether this is a bad question or not, it didn't get so much negative attention just for its (lack of) merit. It started when someone was being condescending to me on a different question and then he got pissy when I called him on his attitude and he started looking for any other questions of mine he could attack, and some others followed him. If you want to be sarcastic/direct/whatever then fine, just don't take it personally if you don't expect people to take your own comments personally. – Brandon Moore May 27 '13 at 19:20
  • 3
    Your question got a down vote from me when I commented your answer for the reasons I mentioned. I have not down-voted your answer. The question was closed as too localized and I think that is correct. It is very unlikely someone will ever benefit from this question. Not even you did that. The vote to close that happens now is from me. – Mikael Eriksson May 27 '13 at 19:33
  • @MikaelEriksson Well now that's not exactly a fair assessment. I fixed the error message, and you yourself suggested you might have helped me had it been right the first time, right? And this is a pretty easy question to find for anyone else who might ever make the same mistake I did. Do you disagree with that, or do you just think it's too localized because it's unlikely anyone else will ever make this same mistake? – Brandon Moore May 27 '13 at 20:30