in reply to Open3 and sending single characters

If there is any chance the the program you are wrapping is bypassing stdio (assuming its written in C) and reading the input buffer direct, then you will probably find it impossible to supply input to it from perl.

A quick way to test if it is reading the input from STDIN, or bypassing that and accessing the keyboard buffer directly is to try supplying the answers to the prompts from a file via redirection.

That is to say, run the program (not your script) from the command line and take it through a sequence that will exercise the prompts you wish to feed from your script.

Then create a simple text file containing the answers to the prompts. Eg. If I use the command "rd /s subdir", I will be prompted with "C:\subdir, Are you sure (Y/N)?" so I create a file called y.txt that contains a single line with the char 'Y' followed by CRLF.

I then invoke the command like this

rd /s subdir <y.txt

and the command accepts the 'Y' from the file and completes the command without interaction.

However, some other programs will not except input supplied from a file this way as they do not read from STDIN. If the program you are trying to wrap is one of these, you have a problem.

It may be possible to 'poke' characters directly into the keyboard buffer from Perl, but I have no idea how you would go about this.


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Replies are listed 'Best First'.
Re: Re: Open3
by John M. Dlugosz (Monsignor) on Nov 20, 2002 at 22:30 UTC
    That would be the Win32 API function SendInput. Call it using the Win32API:: module.