Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Error Levels in Batch Scripting

  • 10-02-2005 4: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