kcott has asked for the wisdom of the Perl Monks concerning the following question:
A quick background: I have Windows 10 with Cygwin installed; I mostly use Cygwin for command line work; I have Perl 5.30.0 installed using Perlbrew.
A quick current situation: I needed Strawberry Perl for a work project; I've just installed 5.30.0 without incident. Output from scripts varies as follows: double-clicking script in File Explorer - output to a separate window (sort of expected); calling perl ./script.pl from the command line - output appears after command (expected); calling ./script.pl from the command line - output to a separate window (unexpected).
Here's some details.
I wanted to check that the correct Perl interpreter was being used. Noting that the output window disappeared almost immediately after double-clicking in File Explorer, I added some code to handle that. Here's the script:
#!/usr/bin/env perl use 5.012; use warnings; say "Platform: $^O"; say "Executable: $^X"; if ($^O eq 'MSWin32') { print 'Enter to close window: '; <>; }
This all worked as expected from Cygwin:
ken@titan /cygdrive/c/Users/ken/tmp $ ./test_platform.pl Platform: cygwin Executable: /home/ken/perl5/perlbrew/perls/perl-5.30.0/bin/perl ken@titan /cygdrive/c/Users/ken/tmp $ perl ./test_platform.pl Platform: cygwin Executable: /home/ken/perl5/perlbrew/perls/perl-5.30.0/bin/perl
What I got with MSWin has raised two questions.
Double-clicking on the script in File Explorer gave the correct output (in a separate window) with the expected prompt:
Platform: MSWin32 Executable: C:\Users\ken\local\opt\strawberry_perl\5_030_000\install\p +erl\bin\perl.exe Enter to close window:
Running as an argument to perl from the command line still has the prompt (which I'd like to get rid of):
PS C:\Users\ken\tmp> perl ./test_platform.pl Platform: MSWin32 Executable: C:\Users\ken\local\opt\strawberry_perl\5_030_000\install\p +erl\bin\perl.exe Enter to close window:
Running without perl returns immediately:
PS C:\Users\ken\tmp> ./test_platform.pl PS C:\Users\ken\tmp>
but a separate window has the (correct) output:
Platform: MSWin32 Executable: C:\Users\ken\local\opt\strawberry_perl\5_030_000\install\p +erl\bin\perl.exe Enter to close window:
Two Questions:
- Is there a way to identify when the output is being presented in a separate window (such that I could change the code so that the "Enter to close window:" prompt only appears in these cases)?
- Why does ./test_platform.pl use a separate window for output when perl ./test_platform.pl does not?
— Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Handling MSWin Script Output -- ParentPID
by Discipulus (Canon) on Sep 11, 2019 at 09:32 UTC | |
by kcott (Archbishop) on Sep 16, 2019 at 05:06 UTC | |
Re: Handling MSWin Script Output
by VinsWorldcom (Prior) on Sep 10, 2019 at 21:26 UTC | |
by kcott (Archbishop) on Sep 11, 2019 at 09:11 UTC | |
by VinsWorldcom (Prior) on Sep 11, 2019 at 10:32 UTC | |
by kcott (Archbishop) on Sep 16, 2019 at 04:20 UTC | |
Re: Handling MSWin Script Output
by Orangutan (Novice) on Sep 10, 2019 at 18:28 UTC | |
by kcott (Archbishop) on Sep 11, 2019 at 08:39 UTC | |
by Orangutan (Novice) on Sep 11, 2019 at 17:34 UTC | |
Re: Handling MSWin Script Output
by Anonymous Monk on Sep 10, 2019 at 08:43 UTC |