2

I know this question has been asked before, but all the resolutions I found did not work for me. Here is what I am trying to do.

I need to be able to run a perl script via command prompt by typing:

helloworld param1 param2

if I try to do this now, my parameters are not captured in @ARGV. However, if I type:

perl helloworld.pl param1 param2

The parameters are captured in @ARGV.

I have done the following from other posts on this topic:

assoc .pl=Perl
ftype Perl="C:\Perl\Bin\perl.exe" "%1" %*

I have also clicked start->deafault programs->Associate a file type or protocol with a program. Searched for .pl and browsed to C:\Perl\bin\perl.exe.

I have also used regedit to change the open value in HKCR\Perl\shell\open\command to read:

(Default) REG_SZ "C:\Perl\Bin\perl.exe" %1 %*

after doing all of this, I am still not able to execute the script by typing:

helloworld param1 param2

Any other comments or suggestions on things I may have missed to get this to work would be greatly appreciated...

  • 1
    Could you upgrade ActivePerl? There's been a lot of work done on it since 5.8.6 (nine years ago). I'd recommend uninstalling it, removing all your Perl related operating system changes, and installing the latest version. It should set everything up itself. – Schwern Mar 22 '13 at 19:03
  • Yeah, I wish I could, this stuff is part of an old process that I need to get limping along for just a little while longer until it goes away. I tried running with a newer version but there were other issues with that.. – user2200504 Mar 22 '13 at 19:11
  • You're leaving out the `.pl` in your `helloworld.pl param1 param2` - is that intentional? – Mintx Mar 22 '13 at 19:20
  • 1
    yes, it is my understanding that by adding .pl to the PATHEXT environment variable, you can also leave the .pl off when executing the script. I was able to do so with XP anyway... – user2200504 Mar 22 '13 at 19:24
  • 1
    Could this be an issue with `REG_SZ` versus `REG_EXPAND_SZ` as noted in this answer: http://stackoverflow.com/a/1695206/100754 ? I don't have a Windows 7 computer right now, so I can't check. – Sinan Ünür Mar 22 '13 at 19:39
  • I am unable to change the entry from REG_SZ to REG_EXPAND_SZ is there some trick to it? I tried deleting the entire key and re-creating it, but it always adds the default value in as REG_SZ and it won't let me delete it ??? – user2200504 Mar 22 '13 at 20:09
  • OK, I got the key changed to REG_EXPAND_SZ but still not working ??? – user2200504 Mar 22 '13 at 20:48
  • Could you use a `helloworld.bat` file which in turn executes `perl helloworld.pl %*`? – David R Tribble Mar 22 '13 at 22:58

2 Answers2

3

You said you had

"C:\Perl\Bin\perl.exe" "%1" %*

but that you changed it to

"C:\Perl\Bin\perl.exe" %1 %*

It should be the former.


With the setup you describe, you should be using

helloworld.pl param1 param2
          ^^^

If you want to omit the .pl, you must add .pl to PATHEXT env var.

>set PATHEXT=.PL;%PATHEXT%

>type a.pl
print "$ARGV[0], $ARGV[1]!\n";

>a Hello World
Hello, World!

(Of course, you probably want to make the change more permanent by changing your startup environment instead of just this shell's.)

ikegami
  • 367,544
  • 15
  • 269
  • 518
0

I downloaded the following application:

http://creativelement.com/powertools/

I used it to create the association of .pl with perl.exe, and I could then run the perl script with out perl or .pl and it would also accept my parameters. I am not sure what it did compared to all the stuff I have been reading in these threads, but I just thought I would share it with everyone.

Thanks