http://www.perlmonks.org?node_id=11105937

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:

  1. 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)?
  2. Why does ./test_platform.pl use a separate window for output when perl ./test_platform.pl does not?

— Ken