Re: How to detect when a console child process is waiting for input?
- From: "Alex Hong" <hctiaa@xxxxxxxx>
- Date: Tue, 3 May 2005 10:21:42 +0800
"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.
.
- Follow-Ups:
- Re: How to detect when a console child process is waiting for input?
- From: Severian [MVP]
- Re: How to detect when a console child process is waiting for input?
- References:
- How to detect when a console child process is waiting for input?
- From: Alex Hong
- Re: How to detect when a console child process is waiting for input?
- From: Severian [MVP]
- How to detect when a console child process is waiting for input?
- Prev by Date: Re: Hidden Partition
- Next by Date: Re: Can't start after replacing GINA DLL
- 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
|