XP_CMDSHELL Question

  • I need help correctly using the xp_cmdshell command.

    This is the command I am trying to run:

    C:\Program Files\Monarch Data Pump\PumpCmd.exe -q -s "MONARCH_JOB_NAME"

    It works fine when I run from the command prompt. But I want to add it to a stored procedure.

    I have tried using the following xp_cmdshell command with no luck.

    exec master.dbo.xp_cmdshell 'dir C:\Program Files\Monarch Data Pump\PumpCmd.exe -q -s "MONARCH_JOB_NAME"', no_output

    Please how do I write this correctly to make it work?

    Thanks

  • Have you tried putting it in a .bat (batch) file and calling that? That's what I usually do with anything more complex than a dir command.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • i think filenames/paths with spaces need to be wrapped in double quotes, right?

    also, are you not CALLING the datapump? why is the DIR command in there?

    exec master.dbo.xp_cmdshell '"C:\Program Files\Monarch Data Pump\PumpCmd.exe" -q -s "MONARCH_JOB_NAME"', no_output

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (12/30/2009)


    i think filenames/paths with spaces need to be wrapped in double quotes, right?

    also, are you not CALLING the datapump? why is the DIR command in there?

    exec master.dbo.xp_cmdshell '"C:\Program Files\Monarch Data Pump\PumpCmd.exe" -q -s "MONARCH_JOB_NAME"', no_output

    xp_cmdshell only deals with one set of double-quotes. Won't work if the second set is needed for the command to work.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (12/30/2009)


    Have you tried putting it in a .bat (batch) file and calling that? That's what I usually do with anything more complex than a dir command.

    GSquared, Thanks. I put it in a batch file and it worked fine. I appreciate your help.

  • You're welcome.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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