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


In reply to Handling MSWin Script Output by kcott

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.