Re: How to run a perl program from the Windows CMD?
by marto (Cardinal) on Mar 06, 2014 at 10:31 UTC
|
Open a command prompt, type the following:
perl -le "print $^X"
Copy the output from above (e.g. the output for me was D:\perl\bin\perl.exe), run the following from the command prompt (remember to change my example path for the output of the first command):
assoc .pl=PerlScript
ftype PerlScript=D:\perl\bin\perl.exe "%1" %*
test.pl will now run the script rather than open it in your text editor. | [reply] [d/l] [select] |
Re: How to run a perl program from the Windows CMD?
by Discipulus (Canon) on Mar 06, 2014 at 10:16 UTC
|
| [reply] [d/l] |
Re: How to run a perl program from the Windows CMD?
by tobyink (Canon) on Mar 06, 2014 at 10:11 UTC
|
perl test.pl
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
| [reply] [d/l] |
|
|
Thank you, but it says it's not a recognizable file :(
| [reply] |
|
|
That perl isn't a recognizable file? Or test.pl isn't?
If the former, are you sure that you've installed Perl correctly?
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
| [reply] [d/l] [select] |
Re: How to run a perl program from the Windows CMD?
by Eily (Monsignor) on Mar 06, 2014 at 10:07 UTC
|
I might be mistaken on that, but I think you can only have Windows open files from the terminal with the default application. That is, the same one that will open by double clicking your file. So if you change it on one context, the other will follow.
If you don't want the default behaviour to be "run perl" for every .pl file, you could always give your test file another extension, like .ple. Or there's the solution of creating a batch file to start your script.
| [reply] |
|
|
Thank you, I saved it at test.sh and now a pop up appears asking me to choose the correct program to open the file.
| [reply] |
Re: How to run a perl program from the Windows CMD?
by Anonymous Monk on Mar 06, 2014 at 10:19 UTC
|
| [reply] |
|
|
Thank you for the awesome articles!
| [reply] |
Re: How to run a perl program from the Windows CMD?
by Stefany (Acolyte) on Mar 07, 2014 at 09:28 UTC
|
Thank you for the replies everyone, I do have Perl installed on my system because I wrote lots of programs with it, for example this - https://github.com/Stefany93/perl-print-r/blob/master/perl.pl
I have no problems running Perl programs in the browser, but I want to learn how to run them in the CMD because that way I could write desktop programs and that will be cool.
Every time I run the commands with perl in the CMD I get the - "'perl' is not recognized as an internal or externalcommand,operable program or batch file."
Although like I said, I did install Perl long time ago and wrote programs with it, I installed it with the xampp package.
Otherwise I think Perl is an awesome language that gets very much under-estimated and people think that Python replaced Perl and that Perl is useless, this is not true. | [reply] |
|
|
| [reply] [d/l] |
|
|
Thank you, I did what you told me, I added Perl to the ENV variables like this:
C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files (x8
+6)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin;C:\xampp\php
+\zend_framework\bin;C:\Program Files (x86)\Lua\5.1;C:\Program Files (
+x86)\Lua\5.1\clibs;C:\xampp\php;C:\ProgramData\Composer\bin;C:\Progra
+m Files\TortoiseSVN\bin;c:\Program Files (x86)\Microsoft SQL Server\1
+10\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
+c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\xampp\perl\bin
+\perl.exe
And when I run perl -v in the CMD like this:
C:\Users\Stefany>perl -v
I get this error - 'perl' is not recognized as an internal or external command,
operable program or batch file.
Please help! | [reply] [d/l] [select] |
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to run a perl program from the Windows CMD?
by Anonymous Monk on May 07, 2017 at 13:13 UTC
|
- Right click 'My computer'
- Select 'Properties' from the drop down list.
- Select 'Advanced'/'Advanced system settings' (depending on OS version)
- Click 'Environment Variables.
- Add the path of perl.exe in 'System Variables'->'Path'.
- open cmd promt
- cd <your_path_where_perl_path_is_saved>
- In case your perl file is saved in D drive then, the type D: in cmd promt
- run the command perl <perl_file_name>
| [reply] |
Re: How to run a perl program from the Windows CMD?
by locked_user sundialsvc4 (Abbot) on Mar 06, 2014 at 16:50 UTC
|
Okay, step one ... do you know that Perl is installed on your system and working? If so, which one (Strawberry, ActiveState, etc.) is it? How do you know?
If you open CMD, and type the word perl -V, with a capital-V, exactly what does or does not happen?
In (I think ...) the System control-panel, is there presently a file-association for .pl? Right now it would seem that there is not one, and Windows is guessing that it is just text to be edited, but it might also be that .pl is right now associated with Sublime Edit. If you right-click, are you given a choice for “Open With ...” ??
| |
Re: How to run a perl program from the Windows CMD?
by Anonymous Monk on Aug 19, 2017 at 04:19 UTC
|
#!/usr/bin/perl
use strict;
use warnings;
use Path::Tiny;
use autodie; # die if problem reading or writing a file
my $dir = path("/tmp"); # /tmp
my $file = $dir->child("file.txt"); # /tmp/file.txt
# Get a file_handle (IO::File object) you can write to
# with a UTF-8 encoding layer
my $file_handle = $file->openw_utf8();
my @list = ('a', 'list', 'of', 'lines');
foreach my $line ( @list ) {
# Add the line to the file
$file_handle->print($line . "\n");
}
| [reply] [d/l] |