BillKSmith, interestingly, if I try to write anything to the UniqFileName.___, it goes back to needing the ENTER. For example:

#!/usr/bin/env perl # started from https://perlmonks.org/?node_id=11106496 => BillKSmith's + version... # as use warnings; use strict; my $pathToMyself = $0; local $, = "\n\t* "; local $\ = $/; open our $foo, '>>', 'UniqFileName.___'; # Look for file in CWD print {$foo} $^X, "0 = $0", "ARGV", @ARGV; restartMe() unless @ARGV and $ARGV[0]>1; sub restartMe { $ARGV[0] ||= 0; print {$foo} "Restarting $pathToMyself 1+$ARGV[0]...\n"; exec("cmd.exe", "/c", $^X, $pathToMyself, 1+$ARGV[0]) or die "cou +ldn't exec $pathToMyself: $!"; }

If I run that code using perl 11106428-11106496.pl or using my association at the command line using 11106428-11106496.pl, I get:

c:\usr\local\apps\berrybrew\perls\system\perl\bin\perl.exe
	* 0 = 11106428-11106496.pl
	* ARGV
Restarting 11106428-11106496.pl 1+0...

Then if I hit ENTER, I get the next block, and ENTER again I get the final block:

c:\usr\local\apps\berrybrew\perls\system\perl\bin\perl.exe
	* 0 = 11106428-11106496.pl
	* ARGV
	* 1
Restarting 11106428-11106496.pl 1+1...

c:\usr\local\apps\berrybrew\perls\system\perl\bin\perl.exe
	* 0 = 11106428-11106496.pl
	* ARGV
	* 2

However, if I run by double-clicking on the script in Explorer, then it generates all three blocks in the UniqFileName.___ right away. With that result, and jcb's suggestion of wperl, wperl 11106428-11106496.pl (from the command line) will also generate all three blocks without typing ENTER. (Seeing jcb's wperl mention reminded me that wperl is supposed to launch without needing the cmd.exe window)

Taking that lesson learned: if I use the original code, if I double-click on the file, it opens up the single cmd.exe for STDOUT, but properly respawns other than that. And from the command-line, if I run with wperl 11106428.pl instead of perl 11106428.pl, then the Tk properly respawns every time (and the STDOUT is lost to wperl's absorption of such.

So, for petro4213, you might want to have a special extension (like .wpl for windows-perl, or .tkpl or .pltk for perl-with-tk), and use an association with wperl.exe rather than perl.exe for that/those extension(s). (If you do, you'll want to make sure you never write to STDOUT or STDERR... or redirect those to some logfile.)


In reply to Re^3: Restarting a Perl script on Windows 10 by pryrt
in thread Restarting a Perl script on Windows 10 by petro4213

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.