Perl 5.32 Perl script run as command found in path receives no arguments

I installed a configured Perl 5.32.1 project on a WIN 10 system using the ‘state deploy’ command. I found that I could not run a script in the path, like x.pl, by simply typing x in a command window. I added .PL to PATHEXT. I then realized that .pl was not associated with any program, so I associated it with the perl.exe in the installation directory. Now a script can be found in the path and run, but there are no command line arguments passed to the script ARGV is empty. If I run perl x.pl arg1 arg2, it works fine.

Is it intended that current versions of Perl can run scripts in the path as the older versions before the state tool could? Should this be set up by the deploy command? Has anyone seen and solved this problem?

Other than this, I found that I can easily configure a Perl project, select needed packages using the state command, and deploy. This solves the loss of ppm plus opens up most of CPAN to Windows systems.

Thanks,

Stewart

Hey @stewartbholt,

Thanks for writing! This is a new issue as far as I know and the documentation doesn’t make an explicit statement on the matter. I’ll ask the dev team for input here.

Also, I was really quite glad to read this:

Other than this, I found that I can easily configure a Perl project, select needed packages using the state command, and deploy. This solves the loss of ppm plus opens up most of CPAN to Windows systems.

… thanks for letting us know!

Cheers!
–zak

After hearing that this is an unknown problem, I started digging. I wrote a script which reads from and and passed it arguments, While it was waiting on input, I used the Task Manager to look at its command line and as I expected the arguments were absent. I searched the registry for “bin\perl.exe” as a value. I found several places, but the following seemed most likely to be involved. This key was likely created when I associated Perl with the .pl extension.
HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command
I added 3 characters to the end of the existing value, ’ %’ resulting in:
“C:\AS\Perl-5.32.1\bin\perl.exe” “%1” %

Now arguments are passed to the script.

The steps I used were:

  1. Dig through the dumbed down MS interface settings to be able to browse to a program to associate with an extension. Set perl.exe for .pl.
  2. Add .pl to the PATHEXT environment variable.
  3. Change the registry entry as noted above.

The above key does not even exist on another system where perl 5.26 was installed by the
AS installer, so there must be more than one way to accomplish this on Windows. With these changes, simply typing the name of a Perl script located in a directory on your PATH will execute it with the arguments passed.

I would still like to hear from AS developers as to whether there will be changes to support using Perl scripts as commands.

Thanks,

Stewart

Hi Stewart, thanks for taking the time to dig into this! There is an alternative way to ensure your arguments get passed, using a command prompt with administrator privilege:

FTYPE Perl=C:\Path\to\perl “%1” %*
ASSOC .pl=Perl

We’ll be looking into performing these actions automatically for perl runtimes installed with state deploy in the near future.

Shaun.

1 Like

While I have nothing to add with regards to Perl script execution (beyond what Shaun already said) I do want to point out that state deploy is largely intended for “install and forget” type of situations. If you intend to actively work on your project (ie. installing / updating packages) you would ideally be using state activate.

Thanks. I set up my project on the web and deployed it on a laptop to have it is a backup place to run an application which processes data once an hour. This also serves as a test of the state tool perl. Your reply brings up some questions: Can I update this deployed perl from the web resident project, if I add modules to it? If not, how to uninstall so that I can reinstall?

My main system has 5.26 and was configured via ppm. I plan to switch to an activated 5.32.1 on the desktop as soon as I determine that everything is working on the laptop and I am close to that now. For the cleanest environment, do I need to or should I uninstall 5.26 first?

The state tool documentation is good for documenting the commands and options, but additional documentation would be helpful to make it easy for old PPM users to know the steps to set up a development environment and a production environment. A discussion of how to to update the environments and the differences between activate and deploy and when you would best use each. I had originally done an activate and I think I hit the problem this post described and switched to deploy in hopes it would make the associations. In addition to managing perl projects on my desktop, adding packages and further development of applications, I want to be able to execute perl scripts as commands in any command prompt. Can I have a project deployed for general use and other project(s) activated for adding CPAN packages and incorporating them into applications on the same system? Then at a point, I would want this branch of the project to be deployed. A discussion of this would make switching from perl with ppm to the state tool much easier.

Thanks

Stewart

1 Like

Thanks for the additional information, @stewartbholt! We’ll put this info together for you.

Cheers!
–zak

Thank you. That will be very helpful. I will give feedback and maybe it can evolve into an easy to follow procedure to get someone started.

Stewart

Today I tried to activate a project for the first time. state updated itself at the beginning. The activation fails with messages shown below. Also I cannot successfully uninstall state to start over.
Attempted:
state activate stewartbholt/Perl-5.32.1
… lots of progress bars, looks normal except for closed log file messages…

Something Went Wrong

x Could not update runtime installation
x Not all artifacts could be installed:
Failed to install artifact Text-Tabs+Wrap (2f6c8ccd-5ac7-513f-89af-a8dc7c11d99c) :: Invalid status code: 404

Need More Help?

Run ? state activate --help for general help
Visit the Forum ? State Tool - ActiveState Community

Got a lot of these types of message about closed log file:

Error writing log message: write C:\Users\sholt\AppData\Roaming\activestate\cli-release\state-30112.log: file already closed

Could there be something wrong with my project? Months ago, I deployed it on another system with no problems. Today I updated the project to add:
Latest Commit Aug 6, 2021 Add Crypt::Mac::HMAC
and got a message that the build was complete. Then I tried to activate it on a system where nothing had ever been activated by state.
After errors, I decided to completely uninstall state and start over, but state cannot be uninstalled. Here is what happens:

C:\Users\sholt>state --version
ActiveState CLI by ActiveState Software Inc.
License BSD 3
Version 0.28.4-SHA6258a7b
Revision 6258a7b51216fdf63170330d42a18abbcae6839d
Branch release
Built Wed Aug 4 2021 21:53:09 +0000 GMT

C:\Users\sholt>which state
/c/Users/sholt/AppData/Roaming/ActiveState/bin/state

C:\Users\sholt>state clean uninstall
±-------------+
¦ Uninstalling ¦
±-------------+

Please Confirm
You are about to remove the State Tool, installed language runtimes, and all configuration information. Continue? (y/N)

y
Successfully removed State Tool and related files

C:\Users\sholt>REM Really?

C:\Users\sholt>which state
/c/Users/sholt/AppData/Roaming/ActiveState/bin/state

Any help on how to proceed would be greatly appreciated. I need to use packages not in my production version.

Thanks,

Stewart

Today I tried to activate a project for the first time. state updated itself at the beginning. The activation fails with messages shown below. Also I cannot successfully uninstall state to start over.
Attempted:
state activate stewartbholt/Perl-5.32.1
… lots of progress bars, looks normal except for closed log file messages…

Something Went Wrong

x Could not update runtime installation
x Not all artifacts could be installed:
Failed to install artifact Text-Tabs+Wrap (2f6c8ccd-5ac7-513f-89af-a8dc7c11d99c) :: Invalid status code: 404

Need More Help?

Run ? state activate --help for general help
Visit the Forum ? State Tool - ActiveState Community

Got a lot of these types of message about closed log file:

Error writing log message: write C:\Users\sholt\AppData\Roaming\activestate\cli-release\state-30112.log: file already closed

Could there be something wrong with my project? Months ago, I deployed it on another system with no problems. Today I updated the project to add:
Latest Commit Aug 6, 2021 Add Crypt::Mac::HMAC
and got a message that the build was complete. Then I tried to activate it on a system where nothing had ever been activated by state.
After errors, I decided to completely uninstall state and start over, but state cannot be uninstalled. Here is what happens:

C:\Users\sholt>state --version
ActiveState CLI by ActiveState Software Inc.
License BSD 3
Version 0.28.4-SHA6258a7b
Revision 6258a7b51216fdf63170330d42a18abbcae6839d
Branch release
Built Wed Aug 4 2021 21:53:09 +0000 GMT

C:\Users\sholt>which state
/c/Users/sholt/AppData/Roaming/ActiveState/bin/state

C:\Users\sholt>state clean uninstall
±-------------+
¦ Uninstalling ¦
±-------------+

Please Confirm
You are about to remove the State Tool, installed language runtimes, and all configuration information. Continue? (y/N)

y
Successfully removed State Tool and related files

C:\Users\sholt>REM Really?

C:\Users\sholt>which state
/c/Users/sholt/AppData/Roaming/ActiveState/bin/state

Any help on how to proceed would be greatly appreciated. I need to use packages not in my production version.

Thanks,

Stewart

Hello,

I can mention that I could find on Windows (11 actually but not sure there’s much difference here) a “Uninstall State Tool” app (basically launching a terminal but with the exact command). It appears easily in the menus as a new app; another way to find it back is browsing them by name. I guess it uninstalls all builds and projects, not just one (to be confirmed, I never had several at a same time).
I did that to change from a simple “build” to a “project”.
You can then download and use the install file(s) of the right build(s) on this site.
If you have other builds that work fine, this may be too strong.

Shaun,

I had a problem almost 2 years ago with Active Perl where no arguments were passed to the script when the script name was given as a command and was found on the path. I had found a workaround which I sent to you and you suggested a more simple approach shown below. I cannot find my original email but I suspect that I was just making the registry entries manually.

I have recently built a new Windows system and (reluctantly) installed Windows 11 on it. Everything went fine except I am now experiencing the same dropped arguments problem which had been fixed on W10 by your suggestion. As before, the scripts work fine if I execute them with the Perl command and full path to them. Have you tested this on Windows 11? It would be helpful if the state command set these up, assuming this can be done on W11. The Perl version is v5.32.1 and it was recently activated from my project with the latest state command.

Examples:
D:\Stewart\Perl>testargs 1 2 3 4 5
0 args, hit return

D:\Stewart\Perl>perl testargs.pl 1 2 3 4 5
5 args, hit return

1
2
3
4
5

I have the needed ftype and assoc set for Perl as shown below.

D:\Stewart\Misc\WX>ftype | grep Perl
Perl=C:\Path\to\perl “%1” %*

D:\Stewart\Misc\WX>assoc | grep Perl
.pl=Perl

I should explain that C:\Perl is a link to the actual directory which is: C:\Users\sholt\AppData\Local\ActiveState\cache\1956a4e3. This

Thanks,

Stewart

The state command is intended to NOT make global or permanent user changes, such as setting up registry entries, particularly if you use the “activate” command. Conveniences, like being able to treat a perl script like a command or double-clicking from the desktop, aren’t going to be available, and are going to hobble your ability to switch between Perl versions on the fly.

As a general practice, the file-is-runnable convenience, (which comes from Linux) will limit your options and may not be something you should rely on. Even on Linux, the proliferation of partially incompatible shells over the past decade means that assumptions about the user environment which could be fairly safely predicted in the past are much less likely to be correct now.

Also your use case of making a link from C:\ to your personal AppData folders is problematic because it’s conflicting with the way that Windows manages system-wide exectuables. You should probably investigate using the
state checkout
command instead. That’s intended to give you a permanent, externally accessible, runtime. After using checkout, I would expect that the old way of setting up registry entries manually will still operate on Windows 11.

Thanks for the reply, I have been away from this system for a week. As a reply to my original post, years ago, it was suggested that the FTYPE and ASSOC commands would do what I did in the registry. I looked at the registry entry and saw that I still needed to add %* (not % as in my original description) to the end of the command line. I do not rely on this runnable capability for any automated tasks, just as a convenience from command windows. I will look at changing over to checkout as the basis for the available form the command line version. The state documentation does not say much about what checkout does to setup the runtime environment. It is not on the State Tool Cheat Sheet. Does checkout add the bin directory to the path, or make file associations? How does this differ from activate --default? I think that what is missing from documentation is how to have a version of a language available from the command line and the scripts be runnable and how to test a new version of a language and/or packages without affecting the default version and how to change the default to a new project/branch. I think I am close to understanding it but a writeup on this subject would really help beginners and confirm my understanding.
By the way, I have never seen a problem with using directories which are links in paths or in file associations on Windows. As I only need to use cmd.exe, there is good stability as I see it for what I am doing. (That said, I like Unix/Linux far more than the Windows shell environment.) Since this is only for interactive use, if it becomes unusable, it will not break things where I use the full perl.exe path.