Run a command line in SQL job-

Posted on 2008-11-10
Last Modified: 2012-05-05
I am running a command line in a SQL job,

rmdir /s \\vmpro_server\CDBURNER\PreviousDay

But the problem is, is that it ask "are you sure? (Y/N)" so what is happening is that the job just hangs and doesn't complete the command,

How do i get round this?

Question by:meteorelec
    LVL 26

    Expert Comment

    you can run a command prompt command with xp_cmdshell system stored procedure.
    this command requires sysadmin priviligages... usage i.e.

    set @str = 'rmdir /s \\vmpro_server\CDBURNER\PreviousDay'
    exec master..xp_cmdshell @str


    LVL 2

    Author Comment

    I'm getting this error message when i execute xp_cmdshell:

    Msg 50001, Level 1, State 50001
    xpsql.cpp: Error 1314 from CreateProcessAsUser on line 636

    LVL 11

    Accepted Solution

    To force quiet mode:
    rmdir /Q /S \\vmpro_server\CDBURNER\PreviousDay
    LVL 26

    Expert Comment

    did you try to run the xp_cmdshell with the sysadmin privillages? Otherwise you will get the error.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now