batch file works, job fails

  • I have a job which is running batch file, which eventually does simple things on server like deleting a file and creating a zip file. I run this batch file and it works fine.

    C:cd my_dir

    del my_file.txt

    When same batch file called from a job it says the job was successful but it doesn't delete any file.

    Pulling my hairs on this mystery.

    Anyone have any ideas?

    Thanks.

  • The error may be coming from the batch file itself and not seen by the job. To find out what it is doing add at the end of your command lines in your batch file an output to file.

    Ex:

    del *.tmp > c:\tmp.txt

    This will take alll the generated outputs from the command line and route them to a file where you can read what is being stated.

  • Check rights as well. Might be an NT rights issue.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • bat files always return 0 as their return code. There's a switch to use that causes the last command's return code to be passed back as the return code for the batch.

    You also might be experiencing permission problems that allow you to delete the file but don't allow the ID you have configured SqlServerAgent to do the same thing.

    try putting all your batch files in a special directory and give SqlServerAgent FULL control over it.

  • try this following hirenk...

    1. create bat file delete.bat/delete.cmd

    2. in file...

    @ECHO OFF

    del "destination path of file" space /q

    exit

    save the file and run from jobs or dts under execute process task

    good luck..

    swarn

    SqlIndia

  • Thanks everyone for your suggestions.

    I didn't have any permission issues, but Swarn's version of file did it.

    Swarn, what is different in your file than it would be in normal file? /q is just a quiet mode. Any way but that helped me and my SQL job is working now. Thanks for your help.

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

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