1

Summary

I have seven Windows batch (*.bat) files running continuously on Windows Server 2008 R2. These files simultaneously run into an issue on a recurring basis that causes their cmd.exe (Windows Command Processor) windows to require me to repeatedly press the Enter key in order to continue processing. A system restart is required, since restarting the batch files doesn't change the issue.

Does anyone know of any quirks of Command Prompt that might cause this behavior, or a quick fix that would allow me to work around the issue when it occurs, without having to do a full reboot?

The process, running as normal

The .bat files are running in order to watch for files to appear in specified folders. Once those watched files are seen, code in the .bat files acts upon the watched files. All the while, the .bat files are each printing comments to their individual displayed Command Processor windows in order for me to track their progress as they continue to run.

The issue

Intermittently, something causes all of these .bat files to hang, and all newly started .bat files will have blank Command Processor screens. The strange part is that I am able to advance each of the .bat files by clicking into one of their Command Processor windows and then pressing the Enter key on my keyboard, but Enter has to be pressed constantly to get the .bat file to continue as normal, as it appears as if the .bat file only advances by one printed Command Processor line with each press of the Enter key. This feels as if it is an issue that occurs at the Windows Server OS level, since it impacts all running and newly-opened cmd.exe windows at once.

Solutions, temporary or otherwise

The issue is temporarily resolved by restarting Windows. I hope someone knows of a quick fix with cmd.exe that could allow me to fix the issue when it occurs without restarting. Something like restart certain Windows Services?

I asked ChatGPT about the issue. https://gist.github.com/MrChozo/71327058b4182e4ceeec4b6ec389cbc1.

Its proposed steps are good, but a quick fix would be nice until I can devote time and some of my company's very limited resources to an OS upgrade.

1 Answer 1

0

There is no reference whatsoever to the actions and/or order in which your commands (or which ones are or how they are used) and/or which executables are being used in their batch files or even if there is any obvious hardware deficiency or defect participating/causing failures....

Also, no "File - ERROR.log" (eventvwr.msc) was posted to try to find out some indication of the causes of the anomalies.


However, regarding the following,

Does anyone know of a quirk or quick fix with cmd.exe that would allow me to fix the issue when it pops up without having to do a full reboot?

try:

Option 1. Open the Task manager (Taskmgr.exe) and force close all conhost.exe, cmd.exe, wt.exe, WindowsTerminal.exe processes manually.

or:

Option 2. Create a shortcut in an easily accessible location and use the line below as the path for "Target location":

%ComSpec% /c "for %i in (wt,windowsterminal,conhost,cmd)do %windir%\system32\taskkill.exe /f /im %~i.exe" 

Note. Depending on your real scenario, some of these invoked/involved elements items may not apply:

  • WT.exe
  • CMD.exe
  • ConHost.exe
  • WindowsTerminal.exe

Intermittently, something causes all of these .bat files to hang, and all newly started .bat files will have blank Command Processor screens. The strange part is that I am able to advance each of the .bat files by clicking into one of their Command Processor windows and then pressing the Enter key on my keyboard, but Enter has to be pressed constantly to get the .bat file to continue as normal, as it appears as if the .bat file only advances by one printed Command Processor line with each press of the Enter key. This feels as if it is an issue that occurs at the Windows Server OS level, since it impacts all running and newly-opened cmd.exe windows at once.

Specifically regarding the manifestations described in "Intermittently, something causes all of these .bat files to hang," carefully observe the execution of each batch file and take note of the following:

1. The use of redirection operators when calling each bat and within the commands executed in each file.

  • Pay attention to the implementation of log files with redirection in multiple bat files.

2. Ensure that one bat file does not read from another bat file at the same time, facilitating output feeding.

  • This prevents the cmd.exe from prioritizing which bat to read from and write to during operations.

3. Be aware of executables that might be called by a third file (currently in use).

  • Such files may become corrupted or in use by a second executable invoked by another bat, particularly if multiple executions occur simultaneously.

4. Check if any backup or antivirus software is running that accesses the bat files and/or any files involved/manipulated during the execution of these bats.

  • Be fully aware of what is running in the background at the moment your bats are executed, and if it is using any common files that are also accessed by the bats, as this will help you understand what may contribute to any issues or freezes that occur.

5. Consider potential conflicts related to permissions.

  • This includes access, execution, reading, writing, etc., involving files related to the execution of your bats.

  • Also, if applicable, check for conflicts on network drives or folders and/or the Internet.

6. Examine the logs available in the Event Viewer (eventvwr.msc).

  • Look for error occurrences and identify the files and processes involved in these anomalies.

7. In the Event Viewer, it is also possible to view logs related to hardware behavior.

  • Although it is less likely to be the total or partial cause of the problem, I recommend taking advantage of the time spent searching for records (as mentioned in item 6.) to check for any reported hardware error alerts and the times when these occurrences took place.

  • Consult the suggestion proposed by @DrMoishe Pippik in this specific response regarding hardware failure inquiries in the Event Viewer, particularly concerning the recommended software FullEventLogView.


1
  • 1
    Thank you for your answer, and I hope my edits to it maintain the intent of each of your statements. I will have to try/watch some of these! Commented Sep 30, 2024 at 19:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.