Running Perl script on Windows NT

Discussion in 'Perl Misc' started by Pea, Jan 19, 2004.

  1. Pea

    Pea Guest

    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!
     
    Pea, Jan 19, 2004
    #1
    1. Advertising

  2. Pea

    Ben Morrow Guest

    (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.
     
    Ben Morrow, Jan 19, 2004
    #2
    1. Advertising

  3. 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 ;-)

    Read over perlport for more information.

    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
    for more information.

    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.
     
    James Willmore, Jan 19, 2004
    #3
  4. Pea

    Paul Lalli Guest

    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
     
    Paul Lalli, Jan 19, 2004
    #4
  5. Pea

    Joe Smith Guest

    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/
     
    Joe Smith, Jan 20, 2004
    #5
  6. Pea

    Pea Guest

    Paul Lalli <> wrote in message news:<>...
    > 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:

    use Term::ReadLine;

    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
     
    Pea, Jan 20, 2004
    #6
  7. Pea <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 20, 2004
    #7
  8. Pea

    Pea Guest

    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 <> wrote in message news:<>...
    > Pea <> 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
    >
    > ??
     
    Pea, Jan 21, 2004
    #8
  9. Pea <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 21, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,832
  2. Stephen M
    Replies:
    2
    Views:
    106
    Stephen M
    Apr 16, 2004
  3. Juergen Fenn

    [Newbie] Running a Perl script on Windows

    Juergen Fenn, Oct 8, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    295
    Juergen Fenn
    Oct 9, 2005
  4. Replies:
    4
    Views:
    197
    Josef Moellers
    Oct 27, 2007
  5. Replies:
    4
    Views:
    306
    ccc31807
    Jul 29, 2011
Loading...

Share This Page