markww:
Read perlipc and look at the section named "Using open() for IPC" for an example on how to do that. You may also want to try Super Search for other discussions on the subject.
...roboticus | [reply] [d/l] |
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);
| [reply] [d/l] |
Hi markww,
Have a look @ Section 16 of the Perl Cookbook - there are recipes in there that use IPC::Open3 to control input/output to/from another program.
HTH ,
A user level that continues to overstate my experience :-))
| [reply] |
You probably want to consider moving up to a gui, like Tk, to get input and feed it to your program, or you could use Expect. Read "perldoc Expect", it does what you want.
| [reply] |
or you could use Expect. Read "perldoc Expect", it does what you want.
I thought Expect didn't work on Windows (except possible in Cygwin)?
You probably want to consider moving up to a gui, like Tk, to get input and feed it to your program
Nowhere does he say he needs input form the user. In fact, it sounds like he wants to save the user from having to input constant data.
| [reply] |