Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

script not working

by Raj07 (Initiate)
on Sep 25, 2009 at 04:15 UTC ( #797392=perlquestion: print w/replies, xml ) Need Help??
Raj07 has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone help me out in fixing the error in the following code.The following code launches my application.Here the main window handle is dispayed as 0... An error comes as : "use of uninitialized value in subroutine entry at lines 8,9,12 and 13th.. I am new to perl ..help me out plz....
< 1)use Win32::GuiTest qw/:ALL/; 2)$Win32::GuiTest::debug = 1; 3) my $fgWindow1= 0; # Foreground Window 4) system("c:\\MyApp\\abcd.exe"); 5) $fgWindow1=WaitWindowLike( 0 , "^MyApp Administration"); 6) SetForegroundWindow($fgWindow1); 7) my @Mwnd= FindWindowLike(0 , "^MyApp Administration"); 8) SetForegroundWindow( $Mwnd[ 0 ]); 9) if( not @Mwnd ){ 10) printf( "Cannot find window with title/caption MyApp Administra +tion \n");} 11) else{ 12) printf( "Window handle of MyApp application is %x \n", $Mwnd[ +0 ] ); } 13) if(IsWindowVisible($Mwnd[ 0 ])) { 14) printf("Application launched successfully \n"); } 15) else { 16) printf("Application launching is failed \n"); } >

Replies are listed 'Best First'.
Re: script not working
by Urthas (Novice) on Sep 25, 2009 at 04:39 UTC

    Oh my good Lord, format that code by wrapping it in html code blocks:

    use Win32::GuiTest qw/:ALL/; $Win32::GuiTest::debug = 1; my $fgWindow1= 0; # Foreground Window system("c:\\MyApp\\abcd.exe"); $fgWindow1=WaitWindowLike( 0 , "^MyApp Administration"); SetForegroundWindow($fgWindow1); my @Mwnd= FindWindowLike(0 , "^MyApp Administration"); SetForegroundWindow( $Mwnd 0 ); if( not @Mwnd ) { printf( "Cannot find window with title/caption MyApp Administratio +n \n"); } else { printf( "Window handle of MyApp application is %x \n", $Mwnd 0 ); } if(IsWindowVisible($Mwnd 0 )) { printf("Application launched successfully \n"); } else { printf("Application launching is failed \n"); }

    Anyways, if nothing else you are using $Mwnd 0 when you almost certainly mean $Mwnd[0]. I also see if( not @Mwnd ) instead of if(! @Mwnd), although it's pointless to check this after you've already attempted to use the first element in the call to SetForegroundWindow(). You are also using a superfluous call to printf when print will do just fine:

    print( "Cannot find window with title/caption MyApp Administration \n");
      you are using $Mwnd 0 when you almost certainly mean $Mwnd[0]

      This is just an artifact of PerlMonks turning things in brackets like [0] into links (when the brackets are found outside of <code> tags, and aren't HTML-escaped, of course).  If you click on the xml link at the top of the node, you'll see that the brackets are in fact there in the original input.

      (In cases of misformatted nodes, I usually just cut-n-paste the respective section out of that XML doctext from the browser into my editor. This way I also get the original linebreaks, without the need for manual reformatting. — But this is not meant as an invitation for people to no longer care about proper formatting/tagging... Please!! ;)

        Sorry friends..i shouldn't have submitted the post as it is...it was done mistakenly..
      also the hash %x is used in:

      printf( "Window handle of MyApp application is %x \n", $Mwnd 0 );

      but is nowhere declared or initizialized in the application.
      use strict might be of great use to the user.
        also the hash %x is used
        Actually, %x in this context is not referring to a hash. It is the printf format directive to print as (unsigned) hexadecimal. See the man page for printf.
        I have tried all the ways suggested by you, but still the window hanlde is displayed as 0.I a m using Perl Express 2.5 IDE for my scripting.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://797392]
Approved by GrandFather
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-07-19 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (398 votes). Check out past polls.

    Notices?