none
How to run bat file with xp_cmdshell in SQLServer2005?

    Question

  • How to run bat file with xp_cmdshell in SQLServer?

    run.bat file writers
    c: \ Windows \ Notepad.exe

    I wrote the sql statement
    EXEC xp_cmdshell 'd: \ run.bat';
    GO

    time you run the sql statement that notepad.exe is not running good.

    Monday, November 08, 2010 8:43 AM

Answers

  • Does xp_cmdshell is running well for other commands ?

    Exec xp_cmdshell 'dir d:\'

    If it runs well than fine else you have to enable enable the features of xp_cmdshell  in SQL SERVER 2005 Surface Area Configuration.

    If that is already enable then the command you have written shows gap in between drive and file name.

    It should be this way , means ; remove gaps over there [Believing that batch file exist at D:\ root location only].

    EXEC master..xp_cmdshell 'd:\run.bat';


    Please Vote & "Mark As Answer" if this post is helpful to you. Cheers Prakash Nandwana Bangalore , India
    • Marked as answer by KJian_ Monday, November 15, 2010 7:23 AM
    Monday, November 08, 2010 9:29 AM

All replies

  • What do you mean 'is not running good'? You got the error?
    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Monday, November 08, 2010 9:12 AM
  • Does xp_cmdshell is running well for other commands ?

    Exec xp_cmdshell 'dir d:\'

    If it runs well than fine else you have to enable enable the features of xp_cmdshell  in SQL SERVER 2005 Surface Area Configuration.

    If that is already enable then the command you have written shows gap in between drive and file name.

    It should be this way , means ; remove gaps over there [Believing that batch file exist at D:\ root location only].

    EXEC master..xp_cmdshell 'd:\run.bat';


    Please Vote & "Mark As Answer" if this post is helpful to you. Cheers Prakash Nandwana Bangalore , India
    • Marked as answer by KJian_ Monday, November 15, 2010 7:23 AM
    Monday, November 08, 2010 9:29 AM
  • xp_cmdshell cannot be used for "Interactive" applications like Notepad. Try executing something like exec xp_cmdshell 'dir c:\', it should work fine. Modify the .bat file accordingly


    Pradeep Adiga
    My blog: http://www.sqldbadiaries.com

    Recent posts on my blog
    Monday, November 08, 2010 9:34 AM
  • Run this command in your "Run" (Start menu --> Run). It should run there.

    Secondly, there should not be spaces in the path as you have specified "c: \ Windows \ Notepad.exe". It should be like "c:\Windows\Notepad.exe".

    Try it and please specify error description in case you get an error.


    Please visit my Blog for some easy and often used t-sql scripts
    Monday, November 08, 2010 9:35 AM