To respond to
ikegami and
Bloodnok at the same time, I guess Ikegami is right, no Expect on Win32 (unless Cygwin). Also IPC::Open3 will not work on Win32 reliably, although on linux it would be the ideal solution. See
Perl/Tk App and Interprocess Communication The problem is with select on the READ filehandle. You may be able to use IPC::Open3 if you know for sure what the prompt will be from the exe, and you can just feed it your data with a little time delay in between.
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
my ($age, $height, $weight) = (50,72,250); #yeah I'm fat :-)
#my $pid = open3(\*WRITE, \*READ, \*ERROR, 'somecmd.exe');
my $pid = open3(\*WRITE, \*READ,0,'somecmd.exe');
#if \*ERROR is false, STDERR is sent to STDOUT
#send query to cmd
print WRITE "$age\n";
#give cmd time to output
select(undef,undef,undef,.5);
print WRITE "$height\n";
select(undef,undef,undef,.5);
print WRITE "$weight\n";
select(undef,undef,undef,.5);
#get the answer from cmd if needed
chomp(my $answer = <READ>);
print "$answer\n";
waitpid($pid, 1);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.