• DOS batch file woes

    From Spectre@21:3/101 to Anyone Else on Sunday, February 02, 2020 14:09:00
    Alrighty, so I have a section of script that copies a "random" ansi file into the goodbye.ans position as the logoff screen. Its called each time a user logs off oddly enough. Now, in theory to me, I can't see anything logically wrong with it, but somehow I'm ending up with partial copys of files being layered one over the other, so you can end up with a mash up of anywhere from 1-4 images... Heres whats in use at the moment...

    :afterbbs
    if exist \sbbs\test goto post
    echo > \sbbs\test

    rand 13
    if errorlevel 1 set NUM=1
    if errorlevel 2 set NUM=2
    if errorlevel 3 set NUM=3
    if errorlevel 4 set NUM=4
    if errorlevel 5 set NUM=5
    if errorlevel 6 set NUM=6
    if errorlevel 7 set NUM=7
    if errorlevel 8 set NUM=8
    if errorlevel 9 set NUM=9
    if errorlevel 10 set NUM=0
    if errorlevel 11 set NUM=A
    if errorlevel 12 set NUM=B
    if errorlevel 13 set NUM=C
    copy \goodbye\%NUM%.ans \sbbs\txt\goodbye.ans
    del \sbbs\test

    :post
    goto loop

    As I see it, somehow the script is not seeing the if exist properly and or somehow multiple copies are going on at once. Any thoughts on this lot?

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)
  • From Adept@21:2/108 to Spectre on Sunday, February 02, 2020 14:48:46
    I don't know, but since no one else is answering, I'll speculate in the hopes it helps somehow.

    copys of files being layered one over the other, so you can end up with
    a mash up of anywhere from 1-4 images... Heres whats in use at the

    So you're getting a mashup of images, rather than a single copy, which makes
    me assume that one of a few things are happening:
    1. Something is writing all of them out
    2. There's a loop causing the copy to happen multiple times (and probably somehow copying into a file rather than a clean slate version, I guess)
    3. It's running in parallel

    So, with those in mind

    echo > \sbbs\test

    I don't know the syntax, here. What's echo sending, and to where? My first thought was that it could be echoing everything in the test directory, and
    thus that'd explain why you're getting a mashup of images.

    :post
    goto loop

    Not sure what's happening in the larger loop, but perhaps it's getting back here frequently? Or the "if exist \sbbs\test goto post" bit isn't skipping
    the copy.

    if errorlevel 1 set NUM=1
    if errorlevel 2 set NUM=2

    I remember elsewhere there being a discussion on batch files and "if
    errorlevel 1" meaning "if errorlevel >= 1" (or <=1) rather than strictly
    equal, so if this is somehow a parallel execution sort of thing, maybe
    there's multiple threads doing unpredictable things because of it?

    ...admittedly, that last one is more than a bit of a stretch. I'm mostly just reaching in trying to figure out how you'd get a file with multiple different images if the copy action happened only once.

    Oh, also, would there be any benefit to deleting the goodbye.ans immediately before copying one in? I suppose you'd likely run into a bug where it got deleted but not created, and that'd cause issues.

    But it also occurs to me that maybe you really do have some parallel things going on, if there are multiple copies of this script running at any given time, as could happen with multiple nodes.

    --- Mystic BBS v1.12 A43 2019/03/03 (Windows/64)
    * Origin: Storm BBS (21:2/108)
  • From Spectre@21:3/101 to Adept on Monday, February 03, 2020 17:15:00
    I remember elsewhere there being a discussion on batch files and "if errorlevel 1" meaning "if errorlevel >= 1" (or <=1) rather than
    strictly equal, so if this is somehow a parallel execution sort of
    thing, maybe there's multiple threads doing unpredictable
    things because of it?

    ...admittedly, that last one is more than a bit of a stretch. I'm

    Fresh eyes, fresh mind... This script is running 8 times in parallel..


    If exist /bbs/test goto post (does test exist? If yes skip all the copying) echo > /bbs/test (well seeing as it didn't make one now)

    del /bbs/test (remove the lock file when we're done)
    :post
    goto loop

    They try and test for whether there is already a copy in progress if it isn't then create the "test" file because I'm here now. Generate the random errorlevel, yes it sets the NUM variable with each errorlevel until the errorlevel is equal to or greater than any test errorlevel. So at the end, only
    a single file gets copied once at a time, my first iteration of this whole idea copied every file multiple times until the errorlevel condition was breached. This was cleaner.

    Generally this lock method works, I use it in all my door batch files. So i'm not sure what the problem is here and now. Shrug...

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)