Velocity Reviews > Perl > Running Perl script on Windows NT

# Running Perl script on Windows NT

Pea
Guest
Posts: n/a

 01-19-2004
Hello,
I've searched thru the postings, FAQ, cpan and perldoc but come up
empty. I've written perls on Unix but have just been asked to write a
script which runs on the PC (which is NT) which prompts the user and
then copies files to unix servers. How do I begin? Is the first line
something like this?

#! perl -w

Does the script need to reside and be fun from the Perl directory (in
my case C:\Utils\Perl)?

Which commands prompt the user for an ID & PWD? I'm guessing I will
use FTP to copy the files to unix, should I use Net::FTP?

I'd be grateful for any hints or help,
Thanks!

Ben Morrow
Guest
Posts: n/a

 01-19-2004

http://www.velocityreviews.com/forums/(E-Mail Removed) (Pea) wrote:
> Hello,
> I've searched thru the postings, FAQ, cpan and perldoc but come up
> empty. I've written perls on Unix but have just been asked to write a
> script which runs on the PC (which is NT) which prompts the user and
> then copies files to unix servers. How do I begin? Is the first line
> something like this?
>
> #! perl -w

Windows does not support the #! convention, so the first line is
irrelevant. If it *does* look like

#! perl <switches>

then perl will parse those switches, but this is generally only useful
for setting -T. Anything else you can set more clearly within your
script.

> Does the script need to reside and be fun from the Perl directory (in
> my case C:\Utils\Perl)?

No. You do need to arrange for it to be run by perl, though. There are
several ways of doing this:

1. Name it with a .pl extension and associate .pl with perl (this is
usually done by AS perl). Then when you double-click on the script,
it will run with perl.

2. Make a shortcut to "c:\path\to\perl c:\path\to\script".

3. Use pl2bat or pl2exe to create a .bat or .exe that runs your
script.

4. Install PAR (open a dos box, type 'ppm install PAR') and use pp to
bundle the script up into an exe. If you give pp the right options,
you can make an exe that will run on a machine without perl
installed.

I would generally recommend 2 or 4.

> Which commands prompt the user for an ID & PWD?

It depends how you want to do it. If a DOS box is fine, then use print
and <> as you would under unix: you may want to look into
Win32::Console to make the password not show up. I'm not sure how much
you can do with Win32 console windows. If you want some sort of GUI
box, you will have to create one: I'd recommend using Tk, as it is
very easy to use and (at least recent versions) have a windowsy look
and feel.

> I'm guessing I will use FTP to copy the files to unix, should I use
> Net::FTP?

If you want to use ftp, then Net::FTP is the right way to do it, yes.

Ben

--
We do not stop playing because we grow old;
we grow old because we stop playing.
(E-Mail Removed)

James Willmore
Guest
Posts: n/a

 01-19-2004
On Mon, 19 Jan 2004 10:49:13 -0800, Pea wrote:

> Hello,
> I've searched thru the postings, FAQ, cpan and perldoc but come up
> empty. I've written perls on Unix but have just been asked to write a
> script which runs on the PC (which is NT) which prompts the user and
> then copies files to unix servers. How do I begin? Is the first line
> something like this?
>
> #! perl -w
>
> Does the script need to reside and be fun from the Perl directory (in
> my case C:\Utils\Perl)?
>
> Which commands prompt the user for an ID & PWD? I'm guessing I will
> use FTP to copy the files to unix, should I use Net::FTP?
>

If you coded properly, you can run the scripts that you've written for a
*NIX platform on a Windows platform with little change.

If you have not coded properly, then you will have trouble

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt

a fortune quote ...
Mosher's Law of Software Engineering: Don't worry if it doesn't
work right. If everything did, you'd be out of a job.

Paul Lalli
Guest
Posts: n/a

 01-19-2004
On Mon, 19 Jan 2004, Pea wrote:

> Hello,
> I've searched thru the postings, FAQ, cpan and perldoc but come up
> empty. I've written perls on Unix but have just been asked to write a
> script which runs on the PC (which is NT) which prompts the user and
> then copies files to unix servers. How do I begin? Is the first line
> something like this?
>
> #! perl -w
>
> Does the script need to reside and be fun from the Perl directory (in
> my case C:\Utils\Perl)?
>
> Which commands prompt the user for an ID & PWD? I'm guessing I will
> use FTP to copy the files to unix, should I use Net::FTP?
>
> I'd be grateful for any hints or help,
> Thanks!

Have you actually downloaded and installed perl on the PC yet? If not,
you have a few options. The first would be to download the CygWin
packages, and make sure you include Perl when you're setting it up. This
would give you a faux-Unix shell within Windows itself, from which you
could build your perl-for-windows scripts.

The other option, my preferred, is to use ActiveState's distribution of
Perl, found at http://www.activestate.com. Download and install Perl.
The installation process will associate .pl and .plx files with the perl
interpeter. The shebang doesn't matter as much in Windows as it does in
Unix, but most people use one similar to this:
#!perl.exe -w

As for how you're copying files, that's another matter entirely. What do
you mean by "prompt the user for an ID & PWD"? If you've "written perls
on Unix", then surely you must know basic I/O with print and <STDIN>,
right?

Paul Lalli

Joe Smith
Guest
Posts: n/a

 01-20-2004
Pea wrote:

> I've just been asked to write a
> script which runs on the PC (which is NT) which prompts the user and
> then copies files to unix servers.

The other reponses to your posting have good info on running Perl on NT,
but the problem as described does not have to use perl.

Start -> Programs -> Cygwin -> Cygwin Bash Shell
bash# scp -p dir1 username@host:/tmp
bash# rsync -av -e ssh dir2 username2@host:/var/tmp

--
I love my TiVo - http://www.inwap.com/u/joe/tivo/

Pea
Guest
Posts: n/a

 01-20-2004
Paul Lalli <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)> ...
> Have you actually downloaded and installed perl on the PC yet? If not,
> you have a few options. The first would be to download the CygWin
> packages, and make sure you include Perl when you're setting it up. This
> would give you a faux-Unix shell within Windows itself, from which you
> could build your perl-for-windows scripts.
>
> The other option, my preferred, is to use ActiveState's distribution of
> Perl, found at http://www.activestate.com. Download and install Perl.
> The installation process will associate .pl and .plx files with the perl
> interpeter. The shebang doesn't matter as much in Windows as it does in
> Unix, but most people use one similar to this:
> #!perl.exe -w
>
> As for how you're copying files, that's another matter entirely. What do
> you mean by "prompt the user for an ID & PWD"? If you've "written perls
> on Unix", then surely you must know basic I/O with print and <STDIN>,
> right?
>
> Paul Lalli

Perl is already installed on Windows. I have made some progress since
I posted yesterday. I noticed that Net::FTP isnt' found in \lib.
Since this script will be run on developer's PC's, can I put the
module into the script or should I just have everyone copy Net::FTP to
their PC? I was able to get FTP to work without it, reading the
password and commands from a file, though I will probably change this
now knowing that I am copying files to other NT servers:

print "Which type of file are you copying to DEV? \n";
print "Crystal (.crw) or Envision (.xnv) : \n";

my $type = <STDIN>; if ($type =~ /.crw|.xnv/ ) {
print "Enter file name or file containing list of file names:\n";
my $name = <STDIN>; print "File to be copied is$name\n";
print "Which server? \n";
my $envr = <STDIN>; print "File$name will be copied to $envr \n"; system "ftp -s:$name $envr "; } else { print "Invalid filetype for copy to DEV, exiting... \n"; exit 1; } Tara Tad McClellan Guest Posts: n/a  01-20-2004 Pea <(E-Mail Removed)> wrote: > use Term::ReadLine; I don't see where you are making use of this module, so why include it? > if ($type =~ /.crw|.xnv/ ) {

That will match if

$type = 'foocrwbar'; or$type = 'foo.crw.bar';

(try it and see for yourself.)

I doubt that that is what you want.

if ( $type =~ /^\.(crw|xnv)$/ ) {

or, better:

if ( $type eq '.crw' or$type eq '.xnv' ) {

> print "File $name will be copied to$envr \n";

Have you run this code?

Doesn't the output from this print() look funny?

perldoc -f chomp

> system "ftp -s:$name$envr ";

Wouldn't you like to know if you actually got what you asked for?

!system "ftp -s:$name$envr " or die "problem running ftp program";
or
system "ftp -s:$name$envr " and die "problem running ftp program";

You should also consider using the "system PROGRAM LIST" form of
system() call instead of the "system LIST" form as above.

What will your program do if

$envr = ' ; rm -rf /'; # don't actually try this ?? -- Tad McClellan SGML consulting (E-Mail Removed) Perl programming Fort Worth, Texas Pea Guest Posts: n/a  01-21-2004 Thanks for all of the tips. I think I'm good to go now. Turns out I am copying files from one NT server to another, so I can just do a copy command with the full path and filename instead of FTP. Tara Tad McClellan <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>.. . > Pea <(E-Mail Removed)> wrote: > > > use Term::ReadLine; > > > I don't see where you are making use of this module, so why include it? > > > > if ($type =~ /.crw|.xnv/ ) {

>
>
> That will match if
>
> $type = 'foocrwbar'; > or >$type = 'foo.crw.bar';
>
> (try it and see for yourself.)
>
>
> I doubt that that is what you want.
>
> if ( $type =~ /^\.(crw|xnv)$/ ) {
>
> or, better:
>
> if ( $type eq '.crw' or$type eq '.xnv' ) {
>
>
>
> > print "File $name will be copied to$envr \n";

>
>
> Have you run this code?
>
> Doesn't the output from this print() look funny?
>
>
> perldoc -f chomp
>
>
> > system "ftp -s:$name$envr ";

>
>
> Wouldn't you like to know if you actually got what you asked for?
>
>
> !system "ftp -s:$name$envr " or die "problem running ftp program";
> or
> system "ftp -s:$name$envr " and die "problem running ftp program";
>
>
> You should also consider using the "system PROGRAM LIST" form of
> system() call instead of the "system LIST" form as above.
>
> What will your program do if
>
> \$envr = ' ; rm -rf /'; # don't actually try this
>
> ??

Guest
Posts: n/a

 01-21-2004
Pea <(E-Mail Removed)> wrote:

> Thanks for all of the tips.

Here is one more:

Do not top-post!

Have you seen the Posting Guidelines that are posted here frequently?

[ snip 65 lines of TOFU ]

--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas