CMDEXEC - How to execute multiple DOS commands in one step?

  • I'm trying to execute two DOS commands in one job step, but am unsuccessful.  Is this possible?

    IF EXISTS \\Server\C$\File.txt

        DEL \\Server\C$\File.txt

    ECHO JOB COMPLETED > \\Server\C$\File.txt

    Is a SQL job step limited to one DOS command per step?

    Thanks,   Dave

  • Hi Dave,

     i am not sure if we can execute 2 dos commands at one time. what i undertand from the description above is that u need to delete a file if it exists thru a job. i feel, that you can use the script below in the job and try it out.

     

    DECLARE @result int

    EXEC @result = xp_cmdshell 'dir *.exe1'

    IF (@result = 0)

       PRINT 'Success' <place your commands here>

    ELSE

       PRINT 'Failure' <place your commands here>

     

    hope this helps you.

  • Another way is to put all your dos command in a bat file. Run the bat file from sql job

  • If I put all of the DOS commands in a bat file is there a way to know if each command completed successfully?

    Dave

  • Yes. try exit with different number in your bat

    e.g. :

    EXIT 3

  • I'll give it a try.  Thanks for the help.

    Dave

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

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