pradeep,krishna has asked for the wisdom of the Perl Monks concerning the following question:

Hai monks...

I have two problems in the bellow code.

1) In the bellow code the execution stops after executing the code system('"%windir%\system32\mstsc.exe"');(opening Remote Desktop Connection), And restarts when I close the window poped by the exicution of it. To get the output I got to open another window of the same (mstsc.exe/Remote Desktop Connection) before closing the opened window. now it takes the other window for further execution.

2)After executing the code SendKeys("{ENTER}"); the process must wait till another window appears, but before the popup window appears, the process terminates without executing the following code. I tried with usleep(500000); with use Time::HiRes qw(usleep);, but it is also of no use.

use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys); system('"%windir%\system32\mstsc.exe"'); $Win32::GuiTest::debug = 0; my @windows = FindWindowLike(0, "Remote Desktop Connection"); for (@windows) { print "$_>\t'", GetWindowText($_), "'\n"; SetForegroundWindow($_); SendKeys("{ENTER}"); my @windows1 = FindWindowLike(0, "Windows Security",10); for (@windows1) { print "$_>\t'", GetWindowText($_), "'\n"; SetForegroundWindow($_); SendKeys("P@ssword01"); } }

Please help in solving these.

Thanks in advance.

Pradeep Krishna. :)

Replies are listed 'Best First'.
Re: Controlling the execution.
by shmem (Chancellor) on Feb 03, 2014 at 10:54 UTC
    In the bellow code the execution stops after executing the code system('"%windir%\system32\mstsc.exe"');(opening Remote Desktop Connection), And restarts when I close the window poped by the exicution of it.

    I guess that perl waits for the system call to return. Try

    system('"start %windir%\system32\mstsc.exe"');

    This might help solving (part of) issue 1.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Alternatively, on Windows, you can launch a task without waiting by using

      system( 1, $cmd )

        Thanks a lot monk...

      Thanks a lot monk...

Re: Controlling the execution.
by dasgar (Priest) on Feb 03, 2014 at 14:03 UTC

    For item #1, I would agree with shmem's suggestion of leveraging the start command, which will open a new command prompt to run a command/program and return execution back immediately. For more details, open a command prompt and type start /? to get the help message for the start command.

    For item #2, I would recommend looking into using either the WaitWindowLike() or the WaitWindow() function of the Win32::GuiTest module. I would try running things by hand a few times to get the timing figured out to help decide what is a reasonable time out value to use with either of those functions.

      Thanks u dear friend...