Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How can I close a Windows program called from a my Perl script?

by BrowserUk (Pope)
on Jan 18, 2013 at 20:26 UTC ( #1014117=note: print w/ replies, xml ) Need Help??


in reply to How can I close a Windows program called from a my Perl script?

However, since the Windows program does not routinely close at the end of its processing, the execution never returns to the script.

What is the program, and what do you have to do manually to cause it to close?

If the program you are trying to control is a command line program that requires some additional (command line) keyboard input -- say, "quit\n" -- in order for it to terminate, the solution required is usually relatively simple.

If however, the program is a GUI program that requires mouse (or keyboard input to the application window), that is somewhat harder. Still possible, but it would require more information.

The easiest way to supply us with the information we need to help you, is to tell use what the program is so that we can test our solutions before replying. This assumes that it is a program that comes with the OS, or is freely available for download somewhere on the web.

If the program is proprietary application; or costs money to obtain, be prepared for an extended Q&A session while we work out what you can do to control it.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.


Comment on Re: How can I close a Windows program called from a my Perl script?
Re^2: How can I close a Windows program called from a my Perl script?
by danren924 (Initiate) on Jan 18, 2013 at 21:43 UTC

    The program is, unfortunately, a proprietary GUI program, and not widely available. It does, however, use standard Windows GUI controls or keyboard shortcuts to close, such as "Alt-F, E" or a mouse click on the "X".

    The only command line parameters are the source and destination file names.

    Thanks again.

      Then you might be able to use something like this which starts a copy of notepad aysnchronously (system 1, ...), then waits 10 seconds before sending it the Alt-F X key sequnce to close it:

      #! 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 ); }

      Note: that as coded, this will close all running copies of notepad. To be more selective, see the pod for Win32::GuiTest::FindWindowLike().


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.
      ), then waits 10 seconds before sending it the Alt-F X key sequnce to close it: #! perl -slw use strict; use Win32::GuiTest qw

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-07-11 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (218 votes), past polls