Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Automating user input for a CLI-based program on windows

by nilesh27602816 (Initiate)
on Jun 15, 2010 at 21:50 UTC ( #844940=perlquestion: print w/ replies, xml ) Need Help??
nilesh27602816 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks, I have a CLI-based interactive application, say abc.exe, running on Windows. After invoking abc.exe from a perl script I need to auto-feed the inputs to this application. In other words, I would like to automate the process of running commands on this application through CLI. Perl Modules Expect and Run3 doesn't seems to work on Windows. Read about React and OLE, but no luck. Have any body tried these perl modules on Windows ? Is their any other way to tackle this ? Your time and help is highly appreciated.

Comment on Automating user input for a CLI-based program on windows
Re: Automating user input for a CLI-based program on windows
by Corion (Pope) on Jun 15, 2010 at 22:17 UTC

    The most common approach is to send keystrokes (and mouse clicks if you really need to) via Win32::GuiTest.

Re: Automating user input for a CLI-based program on windows
by chuckbutler (Priest) on Jun 15, 2010 at 23:52 UTC

    From the OP, IPC::Run3::run3 does not seem to work, I have included a working example below. (ActivePerl 5.10.1, IPC::Run 0.043) This will run the program in batch mode, which may or not work, or be what you want in your case.

    use strict; use warnings; use IPC::Run3; my (@fromme, @tome); ## Setup my input... push @fromme, "3*12\n"; push @fromme, "40*4\n"; ## Do it; running CLI calculator, but could be anything unless (run3( "bc.exe", \@fromme, \@tome, \@tome )) { ## STDIN STDOUT STDERR ...for the program print "ERROR in command\n"; } print "Return code = $?\n"; ## Return output while ($_ = shift @tome) { print "$_"; } __END__ ~~Output~~ Return code = 0 36 160

    Maybe update your post with more detail of what you wish to do.

    Good luck. -c

Re: Automating user input for a CLI-based program on windows
by furry_marmot (Pilgrim) on Jun 16, 2010 at 16:31 UTC

    As ALWAYS, it would be helpful if you could provide more information...

    And while you're doing that, is abc.exe blocking keystrokes? If you're unsure what this means, consider if you wrote a Perl script using Term::ReadKey (read the docs), and set it to block keys. This could be a problem. What is it? What does it do? Did you or someone you know write it? (This would be some of the "more info"!)

    In general, run3 should just work if you're using it correctly. Are you using it correctly? What code are have you written? (Hey! More info! Okay, enough snarking.)

    You could also check out Win32::GuiTest, per Corion. OLE works well with objects that respond to OLE commands, but sometimes you just need to use the SendKeys function, which is available in GuiTest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://844940]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-08-28 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls