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

Tough automation question on windows

by kalenz (Initiate)
on Apr 16, 2010 at 14:10 UTC ( #835099=perlquestion: print w/ replies, xml ) Need Help??
kalenz has asked for the wisdom of the Perl Monks concerning the following question:

I'm not sure this is doable. The idea is to automate a windows process. Basically the process in interactive mode runs as follows:
c:>myprogram #### Welcome to myprogram myprogram #mycommand1 results of mycommand 1 were: 1 joe 2 sue myprogram #mycommand2 sue your answer is: 15 myprogram #quit
So: 1) windows runs myprogram.exe, which itself 2) accepts non-system(i.e. myprogram-specific) commands which take input and produce output The goal is to automate this so as to say "run myprogram, then mycommand1, take the second output of the second line and run mycommand2 with this as an argument" Can this be done in perl? Sure I can do system "myprogram", but I am not sure how the rest will be captured and fed into mycommand1,2

Comment on Tough automation question on windows
Download Code
Re: Tough automation question on windows
by Marshall (Prior) on Apr 16, 2010 at 14:33 UTC
    There are ways to automate Windows testing with Perl... You bettcha!

    Amongst other things, take a look at Win32::GuiTest. I was looking for screen shots on the web and came across this: Win32::GuiTest

    CPAN Win32-GuiTest readme

    another automated Win32 GUI testing article

    I'm sure that you will get other ideas here also.
    Search Google with: Win32 Gui test.

    Update: Ooops.. it appears that what is needed for this app is just some control from/of the Win shell. And yes, Perl can do that.

Re: Tough automation question on windows
by BrowserUk (Pope) on Apr 16, 2010 at 15:53 UTC

    You're looking for a windows compatible version of Expect. It doesn't currently exist despite that people having been trying for a long time.

    If a solution is possible, it would probably be based around Win32::Console. Or rather, the Win32 APIs that undrlie that module. But it would probably need to be writen in C or XS and would not be a trivial undertaking.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Tough automation question on windows
by tokpela (Chaplain) on Apr 17, 2010 at 04:16 UTC

    I think you are looking for something like IPC::Run3 which would allow you to run a program, capture the output to a variable, parse the variable and then run another command with parameters derived from the output of the preceding command.

    Below is a contrived example that you can change to meet your own requirements.

    use strict; use warnings; use IPC::Run3; my @command1 = ('batch1.bat', 'BF1_PARAM1', 'BF1_PARAM2'); my ($in1, $out1, $err1); run3 \@command1, \$in1, \$out1, \$err1; chomp($out1); print "BATCH FILE 1: [$out1]\n"; my @command2 = ('batch2.bat'); my ($in2, $out2, $err2); if ($out1 =~ /batch\s+file\s+output/i) { push(@command2, 'BF2-PARAM1'); push(@command2, 'BF2-PARAM2'); } run3 \@command2, \$in2, \$out2, \$err2; chomp($out2); print "BATCH FILE 2: [$out2]\n"; my @command3 = ('batch3.bat'); my ($in3, $out3, $err3); if ($out2 =~ /batch\s+file\s+output/i) { push(@command3, 'BF3-PARAM1'); push(@command3, 'BF3-PARAM2'); } run3 \@command3, \$in3, \$out3, \$err3; chomp($out3); print "BATCH FILE 3: [$out3]\n"; print "Done\n";

    And the batch files I used (make 3 files using the below code and name batch1.bat, batch2.bat, and batch3.bat:

    @ECHO OFF SET PARAM1=%~1 SET PARAM2=%~2 ECHO BATCH FILE OUTPUT: %PARAM1% %PARAM2% EXIT 0

    This results in the following:

    F:\ipctest>perl ipc_run3_test.pl BATCH FILE 1: [BATCH FILE OUTPUT: BF1_PARAM1 BF1_PARAM2 ] BATCH FILE 2: [BATCH FILE OUTPUT: BF2-PARAM1 BF2-PARAM2 ] BATCH FILE 3: [BATCH FILE OUTPUT: BF3-PARAM1 BF3-PARAM2 ] Done

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2014-04-23 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (549 votes), past polls