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




"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.


.



Relevant Pages

  • 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 ... >> When a console is waiting for input, it is generally in ReadConsoleW() ... you'll need to redirect that call ...
    (microsoft.public.win32.programmer.kernel)
  • [RFC][PATCH] fix xconsole.
    ... The console messages may only be redirected once, and root may perform ... TIOCCONS security ... The ioctl TIOCCONS allows any user to redirect console output to another ...
    (Linux-Kernel)
  • Re: Windows CE redirected console
    ... Just like the TELNETD does not replace anything, the CONSOLED is a stand alone Service/Driver instance that doing no more than redirect IO into COM port. ... And it does not depends on OutputTo registry but may need its own way to configure the setting. ... Intel IXP425 line but the console service should be platform neutral) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: How to get stdout/stderr from unmanaged DLL?
    ... But any output from PInvoked calls to these unmanaged DLLs ... I ensure that a Console exists for my application (via ... I know I could redirect to a temp file on the process startup from my ... What do you mean by "batch" mode without a window? ...
    (microsoft.public.dotnet.languages.csharp)