Solved

Running Perl SCripts in Wiin95 DOS prompt?

Posted on 1998-06-08
11
165 Views
Last Modified: 2010-03-05
Hi...
I downloaded and installed Perl 5. The question is...
How do I get scripts to run the way I run them in Unix...

# chmod u+x myScript.
# myScript

I'm new to scripting on the PC, when I type the name of the file it says bad file name or command.

C:\ Perl -v #works fine
regards
0
Comment
Question by:rickyr
  • 5
  • 4
  • 2
11 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1207711
Just like when you type the name of a text file Windows knows .txt means run notepad, you need to associate the extension  .pl with perl so Windows runs it when you type myScript.pl.

(Note that the .pl extension is required, Windows needs the extension to tell file type, unlike Unix which looks at the first line of the file no matter its name).

You can add the association of .pl to perl.exe in My Computer | View | Options | File Types. (There may be an easier way, but since most programs do it automatically I don't need to go ther often). Good Luck!
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 20 total points
ID: 1207712
@REM = '
@ECHO OFF
SET ARGS=
:loop
IF .%1==. GOTO endloop
SET ARGS=%ARGS% %1
SHIFT
GOTO loop
:endloop
perl.exe -S %0 %ARGS%
GOTO endofperl
@REM ';

print "  write your perl code here  \n";

__END__

:endofperl
SET ARGS=

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1207713
Oops, forgot to tell you that the script from my answer must be in a file with extension  .bat  (probably .exe or .com works too;-)
0
 
LVL 6

Expert Comment

by:alamo
ID: 1207714
Ok, so why would you ever do it that way, rather than giving the script a .pl extension and running it directly? Or am I missing something?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1207715
alamo, how do you run it in a command.com, or from within another program?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:alamo
ID: 1207716
From the Command Prompt (which is actually cmd.exe, not command.com). I am actually running NT, but I could have sworn 95 has the same file association capabiolity (though I don't have a 95 machine handy to test with right now).
0
 
LVL 6

Expert Comment

by:alamo
ID: 1207717
Oops.
Researching the issue, I find that while 95 can run files via file extension association same as NT when clicking on them, 95 can't do from a command prompt. I had not realized the 95 command shell lacked that capability. Sorry, ignore my original post.

(In researching this, I did also find a way in NT to run a perl script from the shell without specifying the extension, which I said above was impossible. Oops again).

Thanks for posting that answer, ahoffman, so I didn't waste rickyr's time. However, I am sorely tempted to ask him to reject your answer so I can post "Upgrade to WinNT as the real answer :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1207718
command.com, cmd.exe  doesn't matter, it just works.
I'm trying to reject using of 95 ;-)
In the M$ world it's so cumbersome to do simple things like perl :-(( see my answer

0
 
LVL 3

Author Comment

by:rickyr
ID: 1207719
hi Ahoffman....
I tried it and got.....
C:\mydir myscript.bat
Can't execute myscript.bat.
Label not found
regards
P.S. If your back at work and have the time, I would still like to go thru mail setup for
standalone sparc with no DNS.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1207720
try without  -S  option:

perl.exe %0 %ARGS%

also make shure that perl.exe is in your PATH, or use full pathname.
0
 
LVL 3

Author Comment

by:rickyr
ID: 1207721
Hi...
It worked for the first suggestion "-S", after I edited my PATH
thanx
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

18 Experts available now in Live!

Get 1:1 Help Now