CMonster has asked for the wisdom of the Perl Monks concerning the following question:

I'm doing some Web-based integration work with a Win32 program called ACT!, and I've run into a snag. Using Win32::OLE, one of the object posts an (erroneous) error to the console and waits for a keypress before continuing. Since the error is erroneous, the rest of the program works fine as long as it gets past the keypresses.

From a Web back-end, though, I can't figure out how to trick the OLE process into thinking it's recieved the keypresses. I can close and re-open STOUT just fine, but STDIN doesn't want to budge.

Any ideas?

The code looks a little like this:

use Win32::OLE; use IO::String; use Win32::Console; my $objDatabase; # use existing instance if Act is already running eval {$objDatabase = Win32::OLE->GetActiveObject('ACTOLE.DATABASE')}; die "ACT not installed" if $@; unless (defined $objDatabase) { $objDatabase = Win32::OLE->new('ACTOLE.DATABASE', sub {$_[0]->Close; +}) or die "Can't start ACT"; } # duplicate STDOUT and STDIN because of a bug in ACT # this only works for STDOUT, not STDIN open(TEMPOUT, ">&STDOUT") || die("Cannot duplicate STDOUT: $!"); close STDOUT; # this one doesn't work # my $fake_stdin = "b\na\nd\nthing\n"; # tie *STDIN, 'IO::String', \$fake_stdin; # this one doesn't work, either my $STDIN = Win32::Console->new(STD_INPUT_HANDLE); $STDIN->WriteInput(1, TRUE, 3, 1, 1, 0, 0); # this line is the culprit # it waits for three keypresses $objDatabase->Open('C:\chris\contacts.DBF'); # restore STDIN open(STDOUT, ">&TEMPOUT") || die("Cannot restore STDOUT: $!"); close TEMPOUT; # after this, it works fine

Any ideas or suggestions would be greatly appreciated.

Replies are listed 'Best First'.
Re: Win32::OLE redirect STDIN?
by nakor (Novice) on Jun 22, 2001 at 00:34 UTC
    You might try adding a $STDIN->WriteInput(1, FALSE, 1, 1, 1, 0, 0) after the ->WriteInput(1, TRUE...) to simulate a full keypress, not just a key-down. Also, you could try actually finding out the VK_ code for ENTER and use that rather than just using 1.

      You might try adding a $STDIN->WriteInput(1, FALSE, 1, 1, 1, 0, 0) after the ->WriteInput(1, TRUE...) to simulate a full keypress, not just a key-down. Also, you could try actually finding out the VK_ code for ENTER and use that rather than just using 1.

      Okay, I made the following modifications:

      my $STDIN = Win32::Console->new(STD_INPUT_HANDLE); $STDIN->WriteInput(1, 1, 1, 32, 57, 32, 0); $STDIN->WriteInput(1, 0, 1, 32, 57, 32, 0);

      This should simulate one full keypress (1 then 0) of the space bar (32/57) with no modifier keys pressed (the last 0). Still no dice. The program still asks for three keypresses.

      Incidentally, creating a similar Console for STDOUT doesn't catch the output the way that close STDOUT does. Am I just using the module incorrectly? I've found bugger all for Win32::Console documentation.

      Thanks again,
      ~chris

Re: Win32::OLE redirect STDIN?
by Anonymous Monk on Jun 21, 2001 at 23:22 UTC
    What about closing (and not reopening) STDIN. Because it doesn't really want the data from STDIN it stands to reason that there are no errorchecks at the read. If the read fails with an error, the program goes on.

      What about closing (and not reopening) STDIN.

      I tried duping and closing STDIN as well, the same way STDOUT is closed in the code. There was no effect; the OLE process still expected keypresses.