<?xml version="1.0" encoding="windows-1252"?>
<node id="1014149" title="Re^3: How can I close a Windows program called from a my Perl script?" created="2013-01-18 17:52:32" updated="2013-01-18 17:52:32">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;Then you might be able to use something like this which starts a copy of notepad aysnchronously (&lt;c&gt;system 1, ...&lt;/c&gt;), then waits 10 seconds before sending it the Alt-F X key sequnce to close it:&lt;code&gt;
#! perl -slw
use strict;
use Win32::GuiTest qw[FindWindowLike SetForegroundWindow SendKeys];

system 1, q[notepad.exe];

Win32::Sleep( 10000 );

for ( FindWindowLike( undef, 'Notepad' ) ) {
    SetForegroundWindow( $_);
    SendKeys( '%fx', 5 );
}
&lt;/code&gt;

&lt;p&gt;Note: that as coded, this will close &lt;b&gt;all running copies&lt;/b&gt; of notepad. To be more selective, see the pod for [mod://Win32::GuiTest]&lt;c&gt;::FindWindowLike()&lt;/c&gt;.


&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;), then waits 10 seconds before sending it the Alt-F X key sequnce to close it:
#! perl -slw
use strict;
use Win32::GuiTest qw</field>
<field name="root_node">
1014114</field>
<field name="parent_node">
1014135</field>
</data>
</node>
