Re: How to detect when a console child process is waiting for input?



On Tue, 3 May 2005 10:21:42 +0800, "Alex Hong" <hctiaa@xxxxxxxx>
wrote:

>
>"Severian [MVP]" <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> ????
>news:7hkd71hempijvo36pj268ossbkfr9l4sqt@xxxxxxxxxx
>> On Mon, 2 May 2005 15:34:16 +0800, "Alex Hong" <hctiaa@xxxxxxxx>
>> wrote:
>>
>> >I am writing a program that tests console programs by creating them as
>child
>> >processes and redirecting their input/output. And I would like to know
>when
>> >the console child process is waiting for input, so that I can give them
>> >input at a proper time. But the MSDN library only offers a
>> >WaitForInputIdle() function which will always return true with a console
>> >program. Is there any way to decide if the child process is waiting for
>> >input?
>>
>> When a console is waiting for input, it is generally in ReadConsoleW()
>> (I'm not sure if this is true if you've redirected its input to a
>> pipe, but the same general method should work; more info below.)
>>
>> 1) Create a named event to check in your monitoring program.
>>
>> 2) Make your program a debugger, and when loading the destination
>> console app, redirect ReadConsoleW in its import table to a routine of
>> your own (which you have injected into the process). I have seen
>> articles on MSDN describing how to do this.
>>
>> 3) This injected routine should set an event then call the real
>> ReadConsoleW(). In your monitoring program, the event will be signaled
>> when the console is waiting for input.
>>
>> If a console program reading from a pipe uses a call other than
>> ReadConsoleW (I haven't checked), you'll need to redirect that call
>> and verify that it is reading from your pipe (perhaps by using a
>> named, rather than anonymous, pipe) before calling SetEvent.
>>
>> Another option would be for your monitoring program to set a
>> breakpoint on ReadConsoleW; then immediately continue the monitored
>> process and write to its input.
>>
>> This is all rather complicated; if I think of an easier method I'll
>> post again.
>>
>> --
>> Phillip Crews aka Severian
>> Microsoft MVP, Windows SDK
>> Posting email address is real, but please post replies on the newsgroup.
>
>Thanks very much for your help.
>If the console program is written by java, will it be using ReadConsoleW( )?
>Now that all ( at least most ) console programs can read redirected input, I
>am assuming that there can be some kind of a system call that all console
>programs use to read from std input. If there is, then I can simply redirect
>that system call. But if they use differnet system calls, then I may have to
>redirect all of them, which can be really heavy for me.

Test it by using Process Explorer (http://www.systinternals.com). When
a console is doing "normal" input, you'll see ReadConsoleW() on the
stack (assuming you have MS symbols loaded from the symbol server).

Then, run your app with standard handles redirected and use procexp to
see if you see the same system call or something different.

Here is what the console stack looks like when cmd.exe is waiting for
input:

http://www.severian.org/MVP/procexp_cmdstack.png

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.



Relevant Pages

  • Re: How to detect when a console child process is waiting for input?
    ... >>the console child process is waiting for input, so that I can give them ... > When a console is waiting for input, it is generally in ReadConsoleW() ... you'll need to redirect that call ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to detect when a console child process is waiting for input?
    ... >I am writing a program that tests console programs by creating them as child ... When a console is waiting for input, it is generally in ReadConsoleW() ... you'll need to redirect that call ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to detect when a console child process is waiting for input?
    ... the console child process is waiting for input, so that I can give them ... WaitForInputIdlefunction which will always return true with a console ... Create a named event to check in your monitoring program. ... you'll need to redirect that call ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Cant send a fax
    ... I can hear the fax noises from the ... But it seems as though the fax console dosen't reply. ... beeps like a call waiting beep. ... I know it's not call waiting because I don't ...
    (microsoft.public.windowsxp.help_and_support)
  • RE: 2.6.9: serial_core: uart_open
    ... Thanks for the suggestion of setting the modem termio to a copy of the xterm ... unresponsive at the console and to telnet sessions. ... Note that this test is being done through an xterm session. ... clear the local flag, then open, waiting for modem control. ...
    (Linux-Kernel)