Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

[FIXED] File association on Windows

by stevieb (Canon)
on Jan 18, 2021 at 23:17 UTC ( #11127078=perlquestion: print w/replies, xml ) Need Help??

stevieb has asked for the wisdom of the Perl Monks concerning the following question:

Update: Fixed.

Good day fellow Monks,

I'm trying to fix an issue with berrybrew in that when a user wants it to manage Perl's .pl file extension, the user is required to hit ENTER twice to get the output displayed to the screen when running a script from the CLI.

I thought I had the problem resolved on one system, but it exhibits the undesired behaviour on a second one. I'm wondering if a kind monk who's got access to Windows systems can test it out for me.

Repro steps:

  • Download and extract a portable version of Strawberry Perl
  • Open a command prompt with elevated privileges
  • Fetch and write down the existing .pl file association, if applicable: assoc .pl
  • Set a temporary file association: assoc .pl=tempPerl
  • Set the association's command: (where 'path' is the absolute path to the top level directory of your portable strawberry instance): ftype tempPerl="C:\path\perl\bin\perl.exe" "%1" %*
  • Create a test script somewhere, say the desktop: use warnings; use strict; print "hello, world!\n";
  • Exit the command prompt, open a new one (doesn't need to be admin this time)
  • Run the script *without* explicitly specifying the interpreter: C:\Users\steveb\

Desired outcome: That the words "hello, world!" will be displayed in the console without having to hit ENTER more than once.

When you are said and done testing, and you did in fact have an association set up previously, simply run assoc .pl=whatever_you_wrote_down to revert your system back to original configuration.

I don't know if it's the VM I'm working on is messed up somehow due to development work or not, which is why I'm hoping someone else can test for me. Both of my machines are the exact same version of Win10.

Thanks for any of those who can help me out.



Replies are listed 'Best First'.
Re: File association on Windows
by stevieb (Canon) on Jan 19, 2021 at 08:55 UTC

    The problem wasn't the berrybrew code, nor how I was implementing the changes. Something went awry with my development environment that was causing the issue. I stood up two new separate VMs and can't reproduce the problem, so essentially the undesired behaviour I was trying to fix is definitely fixed.

    I don't know where in the dev VM the problem lies, nor do I really care to spend any further time troubleshooting, so I'm just dumping the VM and configuring a new dev system.

      I was investigating a bit and, no is not fixed :)

      I avoid file type association and I always do: perl in the command prompt. I associate .pl and .pm files with my text editor Notepad++

      I have followed your steps and then in an unpriviledged cmd prompt:

      C>ftype tempPerl tempPerl="C:\EX_D\ulisseDUE\perl5.32.64bit\perl\bin\perl.exe" >assoc .pl .pl=tempPerl >c:\Users\Tizio.Caio\Desktop\

      Notepad++ was launched without any effect of the file type association.

      The registry show what is was set previously and explain the actual behaviour:

      C>REG QUERY HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fi +leExts\.pl HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\OpenWithList HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\OpenWithProgids HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\UserChoice C>REG QUERY HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fi +leExts\.pl\OpenWithList HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\OpenWithList a REG_SZ {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\OpenWith.exe MRUList REG_SZ ba b REG_SZ notepad++.exe C>REG QUERY HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fi +leExts\.pl\OpenWithProgids HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\OpenWithProgids pl_auto_file REG_NONE C>REG QUERY HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Fi +leExts\.pl\UserChoice HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\F +ileExts\.pl\UserChoice ProgId REG_SZ Applications\notepad++.exe Hash REG_SZ TXlP+tcVMI0=

      Then I googled and I found:

      The above tests executed on: Microsoft Windows 10 Pro 0.0.19041 N/D build 19041


      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Thanks for the detailed response!

        I, too, always use perl on all systems, Linux included. In all honesty, I never even use Windows, except to develop berrybrew ironically ;)

        This feature was solely developed because one of my users had asked for it, and since I don't use Windows, didn't notice the problem until another user stumbled across it.

        In your ftype, you're missing a couple of entries. Compare yours:

        tempPerl="C:\EX_D\ulisseDUE\perl5.32.64bit\perl\bin\perl.exe" mine:

        C:\repos\berrybrew>ftype berrybrewPerl berrybrewPerl=C:\berrybrew\5.10.1_32\perl\bin\perl.exe %1 %*

        The %1 is the script name, and %* are any arguments passed to it.

        Output (only hitting ENTER once to execute the command):

        C:\repos\berrybrew>t\data\ Hello, world! C:\berrybrew\5.10.1_32\perl\bin\perl.exe C:\repos\berrybrew>


        use warnings; use strict; print "Hello, world!\n"; print "$^X\n";

        I can't repro the original problem that was reported (having to hit enter twice) on three new systems I've spun up and tried it on, so I'm as content as I can be until it gets wider testing after release and I get actual feedback on it.

        I'll make a note on this thread when I finish the full release with point form notes on how to test it while actually using berrybrew if you or anyone else is interested in testing it in the larger scheme of things.

        As far as registry, I set only HKCR\.pl for the association, and HKCR\berrybrewPerl\shell\open\command for the ftype definition from within the berrybrew library.

Re: File association on Windows
by Anonymous Monk on Jan 18, 2021 at 23:35 UTC

      I've tried both quoting and not quoting, and on the working system, both work equally. On the non-working system, neither quoted or unquoted work.

      Thanks for the links though, but arg passing isn't an issue. It's simply that I have to hit enter twice on one system for the script's output to be displayed, and not on the other.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11127078]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-02-28 08:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found