from file again andas in the last sectionone python program' output is piped to another' input--the more py script in the parent directory but there' subtle problem lurking in the preceding more py command reallychaining worked there only by sheer luckif the first script' output is long enough that more has to ask the user if it should continuethe script will utterly fail (specificallywhen input for user interaction triggers eoferrorthe problem is that the augmented more py uses stdin for two disjointed purposes it reads reply from an interactive user on stdin by calling inputbut now it also accepts the main input text on stdin when the stdin stream is really redirected to an input file or pipewe can' use it to input reply from an interactive userit contains only the text of the input source moreoverbecause stdin is redirected before the program even starts upthere is no way to know what it meant prior to being redirected in the command line if we intend to accept input on stdin and use the console for user interactionwe have to do bit morewe would also need to use special interfaces to read user replies from keyboard directlyinstead of standard input on windowspython' standard library msvcrt module provides such toolson many unix-like platformsreading from device file /dev/tty will usually suffice since this is an arguably obscure use casewe'll delegate complete solution to suggested exercise example - shows windows-only modified version of the more script that pages the standard input stream if called with no argumentsbut also makes use of lower-level and platform-specific tools to converse with user at keyboard if needed example - pp \system\streams\moreplus py ""split and interactively page stringfileor stream of text to stdoutwhen run as scriptpage stdin or file whose name is passed on cmdlineif input is stdincan' use it for user reply--use platform-specific tools or gui""import sys def getreply()""read reply key from an interactive user even if stdin redirected to file or pipe ""if sys stdin isatty()return input('?'elseif sys platform[: ='win'import msvcrt msvcrt putch( '?' script execution context if stdin is console read reply line from stdin if stdin was redirected can' use to ask user