You say this is about interacting with the Unix shell, but your executable's name ends in .exe. While this isn't impossible, it does lead me to suspect that things are not quite as they seem! Are you running a Windows application on Unix under some emulation? That may lead to all kinds of "fun" with I/O.