The problem is that when a program is run under CGI, its STDIN is a pipe to the HTTP server process (where POST data can be read from), which is not a terminal. Looks like an XY Problem. What program do you run under Expect and how does it misbehave?