Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic User input

Status
Not open for further replies.

starface245

Programmer
Jan 28, 2011
6
0
0
US
I got a program, once it execute the program (.exe), it gives 3 options to the User. Option1.. option2.. option3.. Depending on the User input, let say the User select by typing "option1", it runs option1. My question is that is there a way in Perl to write that so the User does not have to type "option1" every time.

I am looking for a method/function do to User input without having the User there.
Without rewriting/edit the original .exe program. Thanks
 
It is possible, but I do not know the best way to do it. In the past, one used the Expect module, but this may or may not work on windows.

- Miller
 
Expect is the way to go (unless the exe accepts input from the command line? Did you look through the documentation?)

IIRC, MillerH is right and the perl implementation of Expect does not work on Windows.

However, ActiveState (the folks who make ActivePerl) offers ActiveTCL which has an Expect module that does work on Windows. Although, when I've used it in the past, the 'interact' function (which turns control back over to the user while keeping the session active) does not work on Windows. If you need that functionality, you'll need to find another solution. To use it, you'd have to learn a little TCL but some searching on google would probably give you enough info in no time.
 
The .exe needs the inputs from the command line.
:(
Other ways?
 
About the last statment, the .exe opens a cmd line to run the program and the inputs from there.
 
After option 1 is done with x amount of time, then it goes to another option like 2 or 3.
 
here my code using Expect...

#!/usr/bin/perl
use strict;
use warnings;
use Expect;

my $selection = "option1"
my $openprogram = system("progam.exe");
my $exp = Expect->spawn($openprogram) or die;
$exp-> send ("$selection");


It does not work :( .. I get error
Cannont exec(0):no such file or directory

Program Died.
 
I finally found my solution and it works!!
I didnt have to use expect, i think my problem was when I try to open the file, I use system. I should have use open. Now I have automatic user input. Thanks everyone for their help and info, learned lots of stuff about Expect and seems very useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top