Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Restarting a Perl script on Windows 10

by pryrt (Abbot)
on Sep 23, 2019 at 14:53 UTC ( [id://11106572]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Restarting a Perl script on Windows 10
in thread Restarting a Perl script on Windows 10

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.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-26 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found