How does cmd.exe handle (or not handle) I/O errors?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

How does cmd.exe handle (or not handle) I/O errors?

#1 Post by dbenham » 26 Jan 2021 20:30

StackOverflow has an interesting question that involves failed output to stderr because of redirection to stdin. https://superuser.com/q/1620933/109090

In my answer I talk about how failed writes to stderr immediately terminate (crash) the cmd.exe process. Somewhere on DosTips I have some posts that discuss the behavior of cmd.exe when writes to stdout or stderr fail. I also have posts that talk about a limit to the size of messages that can be posted to stderr (or stdout). I think they are all in the same thread, but not sure. For the life of me, I cannot find these posts.

I'd be ever so grateful if someone could help me find them.


Thanks

Dave Benham

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How does cmd.exe handle (or not handle) I/O errors?

#2 Post by penpen » 26 Jan 2021 21:18

Do you mean the following topic?
viewtopic.php?t=6881


Edit: You wrote on stackoverflow:
when writes to stdout fail, there is no error message or error returned what-so-ever!
But at least under windows 10 you could get some error message:

Code: Select all

Z:\>echo 1>&0
Das System kann nicht auf das angegebene Gerät schreiben.

Z:\>echo 1>&0 2>nul

Z:\>

penpen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: How does cmd.exe handle (or not handle) I/O errors?

#3 Post by dbenham » 26 Jan 2021 21:51

Wonderful. Thanks penpen. That is definitely one of them, but it is much earlier than I expected.

I'm pretty sure I have some more posts in a later thread (years later?) that revisit the subject. But the parent thread may not have been about I/O errors.

I think I was investigating some inner workings of cmd.exe and I saw output that didn't make any sense. Upon investigation I discovered that ECHO to stdout and/or error message routing to stderr limit the total length of the message. I think if the stderr message exceeded the buffer that it crashed, (or output was truncated?). This led me to revisit how cmd.exe handles I/O errors, and I did so in a more thorough fashion. Sigh - it's all hazy in my brain.


Dave Benham

Post Reply