Run EXE from Stored Procedure

  • Hi,

    Is any way to run any EXE file from SQL Server 2000 >> Stored Proc

    Thanks

  • Might want to put this in a SQL Server 2000 forum, but here's a head start:

    http://www.codeproject.com/KB/database/xyprocedure.aspx

  • include following script in your Stored Proc

    declare @sqlcmd varchar(200)

    SET @SQLCmd = 'copy c:\dba\sampl.xls c:\dba\sampl_2.xls'

    EXEC master..xp_cmdshell @SQLCmd , no_output 🙂

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • getshir (9/22/2008)


    Is any way to run any EXE file from SQL Server 2000 >> Stored Proc

    XP_CMDSHELL is all you need.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • master..xp_cmshell

    executed above command ..

    query result shows me..query executed succesfully..but file is not copied

  • You do realize that this executes on the Server and not on the Client, right?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Hi,

    I have an EXE file which i would like to run, what i am doing is running following script but in void.... 🙁

    declare @sqlcmd varchar(200)

    SET @sqlcmd = 'WinWSSList.exe'

    EXEC master..xp_cmdshell @sqlcmd

    Now what it gives me as output is :

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    What to do ??

    Thanks

    Parth

  • parth83.rawal (10/2/2009)


    Hi,

    I have an EXE file which i would like to run, what i am doing is running following script but in void.... 🙁

    declare @sqlcmd varchar(200)

    SET @sqlcmd = 'WinWSSList.exe'

    EXEC master..xp_cmdshell @sqlcmd

    Now what it gives me as output is :

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    What to do ??

    Thanks

    Parth

    It's telling you that it cannot find this exe file. Be sure to include the path to this EXE. And remember that this is executed on the Server, and not on your Client.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Hi,

    First of all thanks for the prompt reply.

    My EXE is in C Drive only, and it is running fine, if i run from the command prompt.

    and my server and exe both are on server only. some how it is not running.

    Thanks

    Parth

  • try using full path of the executable. So instead of

    SET @sqlcmd = 'WinWSSList.exe'

    use

    SET @sqlcmd = 'C:\WinWSSList.exe'

    @sqlcmd session may open a command prompt somewhere in the binn folder of the SQL where your executable does not exist.

  • parth83.rawal (10/2/2009)


    My EXE is in C Drive only, and it is running fine, if i run from the command prompt. and my server and exe both are on server only. some how it is not running.

    What makes you think that the xp_cmdshell process's starting directory is "C:\"? It probably isn't, which is why should try what I suggested and specify the full path.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Do you till have this problem?

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    By this statement, I understand the 'WinWSSList.exe' cant be executed from Command Prompt.

    Try executing this from command prompt.

    Regards,

    Gautham Akula

  • indeed it is working from command prompt but not working from SQL, 🙁

    and then i changed my approach.....but still i would like to know the answer for that. 🙂

    Thanks

    Parth

  • Run this:

    xp_cmdshell 'dir c:\*.exe'

    Do you see your executable listed?

Viewing 14 posts - 1 through 14 (of 14 total)

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