Squashman wrote:I still would like to see a real world example of no output of a command inside a FOR /F in clause causing cmd.exe to crash like you stated in your first post.
I just spent two hours trying to recreate the script version that had this problem, and failed to reproduce it
Unfortunately I never backed up that failing version. And in-between I did so many changes to attempt to work around this (and around the other issue about returning the exit code) that the code has changed beyond recognition.
Yet I'm positive here's how things happened: I have a parent script that filters the standard output of a child script, which lists selected values from the registry.
After making a change for sorting the values returned by the child script, I ran the parent script with a wrong argument, and entered the name of a registry key that did not exist. And the cmd shell crashed. Big surprise, as I've had all sorts of problems before, but never a cmd.exe crash! I repeated the test several times in a sub-shell (to keep the console open after the sub-shell crash), adding echos here and there to trace progress before the crash. I concluded that the inner script invoked in the for loop output an empty list of values from that non-existing key, then did return control successfully to the parent script. (I saw this by running something like: 'subcommand %1 ^| echo back alive'. Then the parent script crashed cmd before executing the for body.
Then I thought about trying directly at the cmd prompt the 0-times for loop I told you about in the beginning, and it too crashed cmd immediately. So I concluded perhaps too hastily that the 0-times for loop was the root cause, and never thought about preserving the exact source version that caused the crash. And now I can't seem to be able to reproduce it anymore with a for /f