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.


In reply to Win32::OLE redirect STDIN? by CMonster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.