in reply to Perl script stops running on windows after launching another app

This sort of thing actually requires a couple of important steps. You need to spawn a separate process to run the application, and you need to interact with the running application from your script to "push the buttons".

Under Windows Win32::Process is probably the best way to run the application independently of your Perl script.

Interacting with the running application from your Perl script is easiest with Win32::GuiTest. Using either of these modules requires a little work. The following is a very brief example to get you started:

use strict; use warnings; use Win32; use Win32::Process; use Win32::GuiTest; my $fileName = 'delme.txt'; my $filePath = "$ENV{TEMP}\\$fileName"; my $app = "$ENV{SystemRoot}\\Notepad.exe"; my $cmd = "notepad $filePath"; my $ProcessObj; unlink $filePath; Win32::Process::Create ($ProcessObj, $app, $cmd, 0, NORMAL_PRIORITY_CL +ASS, ".") || die ErrorReport (); #FindWindowLike($window,$titleregex,$classregex,$childid,$maxlevel) my @windows = Win32::GuiTest::WaitWindow (qr"^Notepad"i, 3); die "Expected to find Notepad's new document dialog\n" if ! @windows; Win32::GuiTest::SetForegroundWindow ($windows[0]); Win32::GuiTest::SendKeys ("%y"); @windows = Win32::GuiTest::WaitWindow (qr"^$fileName"i, 3); die "Expected to find Notepad\n" if ! @windows; Win32::GuiTest::SetForegroundWindow ($windows[0]); Win32::GuiTest::SendKeys ("Hello World%fs%fx"); sub ErrorReport { print Win32::FormatMessage (Win32::GetLastError ()); }
True laziness is hard work
  • Comment on Re: Perl script stops running on windows after launching another app
  • Download Code