dolly2011 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script to automatically open the IE browser and capture 200 html files. For some reason, after it run 70 html file, it stopped bringing up IE. I could not figure out what went wrong.

The following is my perl script(Active perl, run on the window7):

$file=""; $name=""; $string=""; opendir(CURR,"C:/script") or die "Can't open directory: $!\n"; while(defined($file = readdir(CURR))) { if($file =~ m/(.*)\.html/) { $name = $1; print "name is $name;\n"; print "$file\n"; $capture_cmd = "C:/nircmd/nircmd.exe savescreenshot c:/script/ +$name.png"; $kill_cmd = "C:/nircmd/pskill.exe iexplore.exe"; print "string is $capture_cmd\n"; system (1, "C://iexplore.exe", "-k", "file:///C:/script/$file" +); #for IE sleep 2; if (system ($capture_cmd) != 0) { print "system command failed"; } if (system ($kill_cmd) != 0) { print "kill command failed"; } sleep 10; } } closedir(CURR);

Replies are listed 'Best First'.
Re: Perl on window7
by bart (Canon) on May 03, 2011 at 05:23 UTC
    (Note: currently the code is pretty much unreadable due to lack of formatting.)

    Perhaps you should stay away from actually killing Internet Explorer, and ask it to terminate nicely. You could use Win32::GuiTest (a module with a terribly inappropriate name) for that, and send an Alt-F4 key combination to it.

    Or perhaps you could try to use the same instance of Internet Explorer for everything, instead of starting a new one every single time, perhaps with Win32::IE::Mechanize (with the browser visible).

Re: Perl on window7
by CountZero (Bishop) on May 03, 2011 at 06:09 UTC
    Is there a technical reason why you have to use IE to get the HTML file? It seems --to me at least-- much easier to do so using LWP::UserAgent or even LWP::Simple.

    Update: OK, now I see it. You are not capturing HTML files, you are taking screenshots and of course that will not work with the LWP-modules.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Perl on window7
by cdarke (Prior) on May 03, 2011 at 11:15 UTC
    it stopped bringing up IE. I could not figure out what went wrong.

    Sorry to state the obvious, but it might help if you tested either the return value from system or $? after you run IE.

    Otherwise we can only guess. For example, maybe your pskill is not working and you are hitting some sort of resource limit?