Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Handling MSWin Script Output

by VinsWorldcom (Prior)
on Sep 10, 2019 at 21:26 UTC ( #11105991=note: print w/replies, xml ) Need Help??


in reply to Handling MSWin Script Output

I think it has to do with how .pl files are handled by Windows. This may come down to `assoc` and `ftype` or maybe in the registry. For me (from a cmd.exe prompt, this won't work in PowerShell):

VinsWorldcom@:C:\Users\VinsWorldcom\tmp> assoc | find /i "perl" .pl=Perl_program_file VinsWorldcom@:C:\Users\VinsWorldcom\tmp> ftype | find /i "Perl_program +_file"

Notice, the `ftype` command (for me) returns nothing, but if I look in my registry at HKEY_CLASSES_ROOT\Perl_program_file, I have some subkeys:

HKEY_CLASSES_ROOT Perl_program_file shell Execute Perl Program command = [REG_SZ] C:\Strawberry\perl\bin\perl.exe "%1" %*

Now when I run your commands, with ./ or .\ and with or without `perl` (and also with or without the .pl extension as I have my PATHEXT environment variable to include .pl) from PowerShell and / or CMD.exe, in all the combinations of the above criteria that make sense, I get the same output:

PowerShell

PS VinsWorldcom ~\tmp > .\test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp > ./test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp > perl .\test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp > perl ./test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp > ./test Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp > .\test Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: PS VinsWorldcom ~\tmp >

CMD (note: CMD.exe won't interpret / as \ like PowerShell does)

VinsWorldcom@:C:\Users\VinsWorldcom\tmp> .\test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: VinsWorldcom@:C:\Users\VinsWorldcom\tmp> perl .\test.pl Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: VinsWorldcom@:C:\Users\VinsWorldcom\tmp> .\test Platform: MSWin32 Executable: C:\Strawberry\perl\bin\perl.exe Enter to close window: VinsWorldcom@:C:\Users\VinsWorldcom\tmp>

Replies are listed 'Best First'.
Re^2: Handling MSWin Script Output
by kcott (Bishop) on Sep 11, 2019 at 09:11 UTC

    G'day VinsWorldcom,

    I got the same as you for 'assoc' and 'ftype' in cmd.exe:

    C:\Users\ken\tmp>assoc | find /i "perl" .pl=Perl_program_file C:\Users\ken\tmp>ftype | find /i "Perl_program_file" C:\Users\ken\tmp>

    In the registry, I have exactly the same as you (except I have C:\Users\ken\local\opt\strawberry_perl\5_030_000\install instead of your C:\Strawberry).

    In your PowerShell output, you show everything output to the PowerShell, instead of the commands starting with perl being output in a separate window. Did you do something else to achieve that?

    In cmd.exe, I get much the same as you:

    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: C:\Users\ken\tmp>.\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: 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: C:\Users\ken\tmp>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: C:\Users\ken\tmp>

    So, the answer to Question 1 seems to be to remove the

    if ($^O eq 'MSWin32') { print 'Enter to close window: '; <>; }

    and run all scripts from "cmd.exe".

    — Ken

      I didn't do anything different - all output showed in the PowerShell window I ran the command from - no new window was launched.

      And just a note, I use PowerShell now exclusively - I never use CMD.exe anymore. PowerShell, I've learned, is sooooo much more capable and I've grown to love it over the past year (yes, I was a late adopter - much like how I'm now picking up Python much to my chagrin since everyone at $work uses it).

        "I didn't do anything different - all output showed in the PowerShell window I ran the command from - no new window was launched."

        Orangutan mentioned PowerShell configuration: it may be that we're using different options. I haven't changed anything so, presumably, I have the default configuration. Given I'm only likely to be using PowerShell infrequently, I won't spend any time investigating that further right now; that may change if my usage does.

        — Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2020-05-27 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (152 votes). Check out past polls.

    Notices?