开发者

Parallel/Multithread in CMD

开发者 https://www.devze.com 2023-01-06 09:54 出处:网络
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 fil开发者_StackOverflow中文版e that counts the number of times any key is pressed in an

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 fil开发者_StackOverflow中文版e 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.


    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.

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消