1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Batch file pauses for no reason

Discussion in 'Support' started by element, Apr 4, 2011.

  1. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    Win7 x64, TC 11. Every now and then I see a strange pause in TCC batch execution. The batch file just pauses. All I need to do to get it to move on is to hit Enter in the console window. The pauses are not disk/CPU/network related: no high activity is taking place. Since hitting Enter gets the batch going again instantly, it suggests that it's some weird console quirk. The batch file runs overnight and I don't want to waste a night due to a pause like this. So I run a script that sends Enter keystrokes to the relevant console. It's stupid, but it works.

    How can I tell if it's TCC or Win console doing this? It's next to impossible to debug this since the pauses occur randomly.
     
  2. Kachupp

    Joined:
    Aug 9, 2009
    Messages:
    133
    Likes Received:
    0
    Post the script would be a good start


     
  3. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    Not really. It's 490 lines of complex code and the pauses happen randomly i.e. anywhere. Where it happens in the script changes with each run (otherwise debugging it would be a snap). On a "good" night the whole batch file runs just fine, on a "bad" day you get a pause somewhere. It almost looks like an occasional, slight timing mismatch: TC runs a command, the command takes 1 sec to execute, but TC misses the "command completed" signal, so it just hangs there, waiting.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,859
    Likes Received:
    83
    That's unlikely, as it would require a monstrous Windows bug (which would be biting *everybody*).

    Is this batch file running in a TCMD tab window or in a TCC console window?
     
  5. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    TCC console. A timing bug wouldn't necessarily bite everyone if it arises only under some obscure, rare circumstances. Anyway, it's a speculation.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,859
    Likes Received:
    83
    Given the hundreds of millions of batch files run every day, it pretty much *would* bite everybody!

    Anyway, there isn't any timing involved - TCC just waits for an event from Windows that the child process has ended. If the child were somehow to end before TCC started the wait, the Windows API would return an error that the process already exited. In any case, there isn't any way that TCC would want a keystroke.

    Depending on your commands, it's remotely possible that you're popping up a messagebox window and the keystroke is closing that window. There's an ancient Windows bug that sometimes causes the first popup window to appear underneath the active window, so you might not be able to see it.
     
  7. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    Nope, no hidden msgboxes, I checked in Nirsoft's Window Lister. If it was some command-specific msg, I'd expect it to occur on the same line in the batch file, whereas the stall can happen anywhere. I can't really debug this with breakpoints, because I can't predict where the issue will occur. Does TCC have some kind of a low-level debug mode, so that if it happens, I could examine the most recent TCC-Win communication and figure out what TCC is waiting for? I know about the "debug" directive but it's not low-level enough. I think I need to get down to the level of message traffic between TCC and Win.
     
  8. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,307
    Likes Received:
    39
    It sounds to me as if someone is pressing Pause or Control-S. Or Windows thinks that someone has pressed Pause or Control-S.

    ... Your batch file doesn't use Keystack, does it?
     
  9. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    No manual key presses, no keystack anything. BTW, is there a guarantee that a command line app (zip, xcopy, etc) will always report to Win when it's done? Can a command line app finish without an error, but not report this to Win?
     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,952
    Likes Received:
    30
    Far-fetched, but ... if you have QuickEdit on and left-click (perhaps inadvertently) in the console window, the batch file will continue until it's time to produce output, then stop. It will start again on any keystroke. Of course, you should see a visual indication that you are in "select" mode.
     
  11. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,952
    Likes Received:
    30
    On Mon, 04 Apr 2011 23:02:06 -0400, element <> wrote:

    |No manual key presses, no keystack anything. BTW, is there a guarantee that a command line app (zip, xcopy, etc) will always report to Win when it's done? Can a command line app finish without an error, but *not* report this to Win?

    No. Windows knows when apps terminate (they don't have to report it). Is it
    possible that an external application is pausing, maybe with an error message or
    prompt that you're not seeing for some reason (redirection?)?
     
  12. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    Hm, that's an interesting thought: a warning that's directed away from the console, yet waiting for a reply. It can't be a major error because I'd have noticed if the batch didn't do its job. Next time I see a stall I'll check if it's a command line app and if it could be giving off a non-critical warning.
     
  13. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    QuickEdit is on, but the batch starts its own console when no one's touching the machine. I'd say a stray left-click is unlikely, but I'll double check. Thanks for the tip.
     
  14. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    FWIW, I did some investigating: no redirected warnings, but the stalled console does seem related to external command-line tools: 7-zip, erunt (old-school registry backup), maybe others. If they're called from the batch directly, like this:
    Code:
    7z.exe [args]
    they hang 5-10% of the time (no error, no warning). Adding "start /wait" beforehand seems to fix the problem:
    Code:
    start /wait "7z" 7z.exe [args]
    I wonder if this is somehow related to multi-threading (I'm on 8-core). Perhaps some command-line tools spawn multiple threads and confusion arises as to which thread signifies the end of the command as a whole. "start /win" works because it treats the newly spawned console as a unit (meaning all threads must be finished for the console to close). Just my theory...
     
  15. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,859
    Likes Received:
    83
    The code in TCC for "start /wait" and for waiting for a process to end when at the command line is exactly the same.
     
  16. element

    Joined:
    Jun 1, 2008
    Messages:
    30
    Likes Received:
    0
    Well, "start /wait" has yet to stall on me, so I'll stick to it.
     
  17. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    604
    Likes Received:
    0
    This also seems unlikely, but I know there to be a bug in Windows 7 with multi-threaded apps that sometimes return the thread return code of a child thread instead of the process exit code. It doesn't seem likely that it would cause a stall, but I suppose you could have odd errorlevel testing that would manifest that way.
     

Share This Page