1

I need to run a counter and a timer at the same time, but I'm not sure about how to achieve it.

I have a batch file that counts the number of times any key is pressed in an easy loop made by a goto, once its done (keypress) for the first time, it fires a timer for 1 min; the key pressed in that time, must be stored in another variable.

My problem is that I don't know how to make the loop to continue running while the timer is counting, because I tried two options without success:

  • Calling (inside the same CMD window, the best for me) the timer after the keypress fires the timer, but it waits till timer has finished.
  • Starting the timer in a new window (the chice I thought about in case there's no chance of running both in parallel); and to be the loop aware that the timer finished, I tried switching a global variable before and after, but i can't manage to make it to keep in the main window the last value set in the prompt window (the one with the timer).
  • Hope I explained myself correclty and somebody can help me, thanks, Dan.

    0

    1 Answer 1

    6

    You can run parallel threads in one cmd session. use start command with /B parameter, it will start your batch in the current cmd window.

    Start /B myBatch.bat param1 param2 ... 
    

    you can continue work while myBatch.bat runs in the background (and output to the current window).

    note ^C will not kill it, only ^Break.

    easiest way to make sure task is killed is to end myBatch.bat with exit command.

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.