Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716

    Unanswered: returning BCP status when called from batch file?

    Hi all,

    I looked in what appeared to be pertinent threads, but found no satisfaction (I realize you can't always get what you want, but if I try this time, I've found that I can't even seem to get what I need ??? ).

    OK, seriously folks...

    I have a batch job on windows NT that fires off a series of bcp operations to export data from tables to flat files as a part of daily processing.

    If, for some reason, the bcp fails, is there a way to catch the failure in the batch file? Presently we are seeing the batch file attempt a bcp, which fails (due to a general network error, or something fun like that) and then go skipping happily along to the next bcp without telling us of the failure.

    Suggestions? Thanks!
    Paul
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    i take it you have already looked at the -e and -m arguments.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'm pretty certain that BCP sets the ERRORLEVEL if it fails. Your batch file could check that.

    -PatP

  4. #4
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    Hi guys, thanks for the responses!

    Sean, yes, we have looked at those flags, and use the -e one in most of our scripts. This one is a tad unique, since we have a bunch-o-bcp's and want to bail out if any fail. I suppose we could check the error file's length or use a 'find' to look for identifying text in the error output file, but I was hoping there is something like ERRORLEVEL to check (for ease of implementation).

    We are testing with the -m flag today, but still, even if it quits, it's not apparent from BOL how the calling script would check for a failure if we set the -m flag to 0 or 1 to cause it to give up on the first encountered error.

    The ERRORLEVEL thing would be great - - just need to test it by forcing a failure. I will have the coder do that (or better yet, try it myself this morning to see what I can see). I just wasn't finding any info anywhere about how a calling script would be able to tell if the bcp call failed.
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •