Solved

@ARGV on WinNT

Posted on 1998-10-29
12
315 Views
Last Modified: 2008-07-03
I've been using perl for a while on Unix and have just installed it on my WinNT machine.

How do I get the script to access parameters from the command line? For example, I want to type:

  popup.pl *.html

to run the script on all of the html files in the current directory.

Under Unix this is done with the @ARGV array, but I can't get it to work on WinNT, and I can't find anything in the documentation or FAQs about it.

thanks!
slugger
0
Comment
Question by:slugger
  • 8
  • 4
12 Comments
 

Author Comment

by:slugger
Comment Utility
Adjusted points to 25
0
 
LVL 5

Expert Comment

by:b2pi
Comment Utility
For a complete explanation, take a look at the README.win32 file in the source directory of perl.  In any case, the problem isn't with perl, but with the shell (on Unix, the shell expands the *.html arg on the command line; simply put, NT doesn't).

To get around this, take another look at

perldoc -f glob

Then, for any argument (say, ARGV[0]) that contains wildcards, or even those that don't, just glob the argument.  Thus, to replace the NT ARGV with the basic unix equivalent:

my(@NARGV);
foreach (@ARGV) {
     push(@NARGV, glob);
}
@ARGV = @NARGV;


0
 

Author Comment

by:slugger
Comment Utility
Thanks for replying b2pi; unfortunately I wasn't clear enough in my question. I don't seem to be able to get any arguments at all into the script. For example, if this is my script popup.pl:

foreach $arg (@ARGV) {
      print $arg;
      }

and I type at the command line:

 popup.pl hello goodbye

I get nothing printed. Perhaps I wasn't clear, it's not just a 'glob' issue, it's getting any parameters at all into the script.

Once I get this part figured out I can probably 'glob' to my heart's content.

thanks
slugger
0
 

Author Comment

by:slugger
Comment Utility
My question is really not how to do a glob but how to pass a command line parameter into the script on Win/NT. If my script is popup.pl:

foreach $arg (@ARGV) {
      print $arg;
      print "\n";
      }

and I type at the command line:

       popup.pl hello goodbye

I get nothing printed. Perhaps I wasn't clear, it's not just a 'glob' issue, it's getting any parameters at all into
the script. The same script works fine on Unix.

thanks
ss
0
 
LVL 5

Expert Comment

by:b2pi
Comment Utility
1.) Open up a command window.
2.) Give the command

> assoc .pl

(yes, there is a space between the c and the period)
It should return something like

> assoc .pl
pl=PerlScript

3.) Give the command

ftype perlscript

4.) What does that return?


0
 

Author Comment

by:slugger
Comment Utility
assoc .pl
pl=mks_perl

ftype perlscript
File type 'perlscript' not found or no open command associated with it.


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:b2pi
Comment Utility
(Actually, what I wanted in that last case was

ftype mks_perl


But are you really using mks_perl?  If so, download the latest source or binary distribution from www.perl.com and get with the modern world (I believe that mks is a 4.0)


0
 

Author Comment

by:slugger
Comment Utility
Actually I did download and install the latest perl 5.004_02. I don't know why it's calling mks_perl in this case; when I type "which perl" it is using the new one in my perl5 directory (I added it to the beginning of the path configuration).

At any rate:
ftype mks_perl
mks_perl=d:\perl5\bin\perl.exe %1

This is where my new perl5 installation is. (The mks version is in c:\mks52\mksnt\perl.exe, but I've disabled it.)

Perhaps I need to go into regedit and delete the .pl file type, and then re-type the .pl files?

thanks for all your help.
slugger

0
 

Author Comment

by:slugger
Comment Utility
Ok, I've deleted .pl from regedit and re-associated the .pl file type. I now get:

assoc .pl
pl=pl_auto_file

ftype pl_auto_file
pl_auto_file=D:\perl5\bin\perl.exe %1

slugger
0
 
LVL 5

Accepted Solution

by:
b2pi earned 70 total points
Comment Utility
Theres the problem.  You're telling perl to run the appropriate script (%1), but not to include the other args.

Change it to

pl_auto_file=D:\perl5\bin\perl.exe %1 %*

0
 

Author Comment

by:slugger
Comment Utility
Adjusted points to 75
0
 

Author Comment

by:slugger
Comment Utility
That was it! thanks so much, who would've thought it was something so logical? :-)

(adding a few points since it was harder than I thought.)

slugger
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now