Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Error Levels in Batch Scripting

  • 10-02-2005 05:26PM
    #1
    Registered Users, Registered Users 2 Posts: 1,048 ✭✭✭


    Hey guys. I wonder could anyone help me...
    Using DOS batch scripts, I am running an automated FTP transfer, which pulls a file from a remote location every few hours or so.
    Thing is, I want to be able to 'catch' the errors as they come (like you would in any good OO language!I know though, that Batch programming is not suited to this. :rolleyes:
    For example, a simple 'destination host unreachable' is a common ftp error and its really the only error I would like to deal with in the script. How would I check for an unsuccessful command, in the script? Further more, how do I execute a branching statement from it? Can it even be done??!!

    Any help would be appreciated...


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Read up on ERRORLEVEL. Your program has to support the ERRORLEVEL Command.

    Also you scan from the highest (afair). So something like..

    if ERRORLEVEL == 2 goto label2
    if ERRORLEVEL == 1 goto label1

    That will work, but if you reverse the lines it wont. You can put labels into batch files by preceeding the label with a colon ( : ).


  • Registered Users, Registered Users 2 Posts: 1,048 ✭✭✭BobTheBeat


    Comments are much appreciated!;) But, to be a bit more specific, If I wanted to audit the success of an ftp transfer through a script how would I go about doing so?
    I am thinking I could set a flag within the FTP script in question, like

    FTP etc.etc.ie
    user blah
    blah
    LCD f:/etc/etc/etc
    PUT etc
    DISCONNECT
    BYE

    Could I set a flag at any point in the above, depending on whether the command was a success>?


Advertisement