xp_cmdshell

  • was wondering if anyone knew how to use xp_cmdshell to execute a .bat file. or, if that isn't possible, how i would call a .bat or .exe file from SQL Server 2k.

    Thanks,

    Matt

  • You would execute it as you would from a dos prompt, just within the xp_cmdshell parameters.

    exec master..xp_cmdshell 'c:\folder\runthisfile.bat'



    Shamless self promotion - read my blog http://sirsql.net

  • EMs DTS and SQL Agent Job can also execute OS commands such as batch files. 

    DTS - Execute Process Task

    Jobs - Step Type is Operating System Command (cmdExec)

    hope this gives you options...

     

  • I have been trying to do the same thing in last few days but no luck. I am afraid the just executing following command does not work

    exec master..xp_cmdshell  'D:\InventoryStaging\Batch\UnZip_Files.bat' . This is the result I get: "is not recognized as an internal or external command". And I dont want to use a DTS package.

     

    Thanks,

    Mahsa

     

  • Does the drive mapping exists on the server ? It's likely that the path to the batch file may exists on your PC and not on the server.

     

  • The D: drive is local drive and that is why I don't understand why it does not work. I even copied the  batch file to c: root but still it does not find it.

    Thanks,

    Mahsa

  • Ok, The xp_cmshell did work. Unfortunately while naming my file name I accidently placed a space and that was why sql could not find it. But thank you guys for your help

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply