Re: How to detect when a console child process is waiting for input?
- From: "Severian [MVP]" <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 03 May 2005 01:37:47 GMT
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.
.
- Follow-Ups:
- References:
- How to detect when a console child process is waiting for input?
- From: Alex Hong
- How to detect when a console child process is waiting for input?
- Prev by Date: Replicating a Directory - Accessing / coping files locked by another process
- Next by Date: Re: Hidden Partition
- Previous by thread: Re: How to detect when a console child process is waiting for input?
- Next by thread: Re: How to detect when a console child process is waiting for input?
- Index(es):
Relevant Pages
|