[18463] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 631 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 4 18:15:53 2001

Date: Wed, 4 Apr 2001 15:15:29 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986422528-v10-i631@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 4 Apr 2001     Volume: 10 Number: 631

Today's topics:
    Re: Simple replacement for IPC::Run run() function <goldbb2@earthlink.net>
    Re: Using NET::FTP with authenticating proxy <dlungren@corecomm.net>
        Using perlembed.pod code? bob_waltenspiel@agilent.com
        What level of Perl needed for my system() call to work? <gary@db.stanford.edu>
    Re: What level of Perl needed for my system() call to w <ren@tivoli.com>
    Re: What level of Perl needed for my system() call to w <gary@db.stanford.edu>
        Wrapper To Log Output Of Win32 cmd.exe (Josh Geller)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 04 Apr 2001 21:12:40 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Simple replacement for IPC::Run run() function
Message-Id: <3ACB8F2B.9E6CA5DA@earthlink.net>

Michael Friendly wrote:
> 
> I am unable to install IPC::Run on my 5.004 perl system, and need to
> find a simple replacement for the run() function, which is used in
> another module, in the form
> 
> run \$program, \$input, \$output;
> 
> I can do this with a piped-open, but I'm not sure how to handle
> the fact that the  name of the output variable is passed by reference.
> 
> Here's what I tried.  Can someone help?
> 
> #! /usr/local/bin/perl
> 
> sub run {
>         my ($program, $input, $output) = @_;
>         open(RUN, "$$program $$input|");
>         while ($in = <RUN>) {
>                 $lines .= $in;
>         }
>         print $lines;
>         $$output = $lines;
> }

This looks good, [aside from $lines and $in not being declared] although
it would probably be better to write it as:

sub run {
	my ($program, $input, $output) = @_;
	$$output = qx[$$program $$input];
}

> 
> $program = "ls";
> $input = '*.pl';

Where are these declared?  You ought to be using strict, and declaring
all of your variables.  This here can be done perfectly well using:

my ($program, $input, $output) = qw(ls $.pl);

The fact that the right-hand list has only two things results in undef
being assigned to $output, which is perfectly ok.

> 
> run \$program, \$input, \$output;

Looks ok.

> 
> print "Got:\n$$output";

Umm, no.  Write this line as simply:

print "Got:\n$output";

Because although a reference to $output was passed to run, $output is
still a normal string.

> exit;

-- 
Sometimes the journey *is* its own reward--but not when you're trying to
get to the bathroom in time.


------------------------------

Date: Wed, 04 Apr 2001 16:09:25 -0500
From: Don Lundgren <dlungren@corecomm.net>
Subject: Re: Using NET::FTP with authenticating proxy
Message-Id: <3acb8d58$0$12817$1dc6e903@news.corecomm.net>

I did get it working. What I found was that I needed to do two logins.
Apparently when I tried that the first time I must have had something else
wrong because after I went in and recreated the 2 login script it ran fine...
Boy do I feel dumb... Hey maybe too much caffine that day...

The script that works with this kind of firewall is as follows:

# Firewall access information
$firewallname="ftpgate0.somewhere.com";
$firewalluser="someuser";
$firewallpassword="someuserpassword";

# FTP Server address, login and password
$ftpusersite='otheruser@www.somewhereelse.com';
$password="otheruserpassword";

open (STDERR,">$errorreport");
open(FILE,">$localrepfilename");

# Connect to firewall
print "Connecting to $firewallname...";
$ftp=Net::FTP->new ($firewallname) or errormessage("Can\'t connect to Firewall
$firewallname - $@ | $!\n");
print "OK\n";

# Login to firewall
print "Login to firewall as $loginname...";
$ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t login as
$firewalluser/$firewallpassword- $!\n");
print "OK\n";

# Login to ftp site
print "Follow on Login as $ftpusersite...";
$ftp->login($ftpusersite,$password) or errormessage("Can\'t login as
$ftpusersite/$password $!\n");
print "OK\n";

####### balance of script omitted ##########

Don Lundgren


Terrence Monroe Brannon wrote:

> 1- you might run this with the Debug flag of Net::FTP set so that we could
> see exactly where it fails
> 2- I have used Net::FTP with the type of proxy you are dealing with. It
> wasn't very hard. I looked at the Net::FTP docs and I think you are doing
> the wrong thing by attempting to log into your proxy server with the login
> method. The docs do state:
>
> http://theoryx5.uwinnipeg.ca/CPAN/data/libnet/Net/FTP.html
>
> that an authorize method is called internally to handle negotiation of the
> firewall. The login argument is for getting into the FTP site, *not* the
> proxy, per the docs...
>
> What you have to do is configure Net::FTP when you download and install it
> (it's in the libnet package) so that it has the uname and passwd for the
> proxy in it's internal config file... that is what I did.
>
> Don Lundgren wrote:
>
> > I am having a bear of a time with an ftp through a proxy server
> > requiring authentication.What we have is a situation where the script is
> > running on an NT machine running ActiveState Perl that is doing a ftp
> > connection to the firewall with a userid & password once that happens it
> > then needs to send the command "user someone@someserver.com" it will
> > then need to enter the password for the follow on server. I have tried a
> > few variations on this and have not had any luck. Each test says that
> > all went well but does not return the directory listing. When I run the
> > script from outside the firewall and reconfigure it to not use the
> > firewall all runs fine and I get my directory listing.
> >
> > The ultimate goal is to replace a simple batch file that has no logging
> > or error correction with the perl script which will do both. The basic
> > commands that the batch file is running are as follows:
> >     open ftpgate.somewhere.com
> >     abcuser
> >     userpassword
> >     user userxyz@ftp2.SomeOtherPlace.com
> >     userxyzpassword
> >     < balance of commands ommited to shorten >
> >
> > If there is any way I can get you to take a quick look at the scripts
> > below and see if anything pops out at you that would be great. What I
> > have tried so far is as follows:
> >
> > #### First Attempt ##################################################
> > # Firewall access information
> > $firewallname="ftpgate.somewhere.com";
> > $firewalluser="abcuser";
> > $firewallpassword="userpassword";
> >
> > # FTP Server address, login and password
> > $ftpname="ftp2.SomeOtherPlace.com";
> > $ftpusersite='userxyz@ftp2.SomeOtherPlace.com';
> > $loginname="userxyz";
> > $password='userxyzpassword';
> >
> > # Remote directory you wish to download from (SOURCE)
> > $remotedirname="/motftp";
> > # Connect to firewall
> > print "Connecting to $firewallname...";
> > $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> > connect to Firewall $firewallname - $!\n");
> > print "OK\n";
> >
> > # Login to firewall
> > print "Login to firewall as $loginname...";
> > $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> > login as $firewalluser/$firewallpassword- $!\n");
> > print "OK\n";
> >
> > # Login to ftp site
> > #print "Follow on Login as $ftpusersite...";
> > $ftp->user($ftpusersite) or errormessage("Can\'t do second login as
> > $ftpusersite - $!\n");
> > $ftp->pass($password) or errormessage("Can\'t do second login password
> > as $password - $!\n");
> > print "OK\n";
> >
> > #### Get directory listing for specific directory on follow on machine
> > ####
> > &messageprint ("Get directory listing of $remotedirname...");
> > my @lines=$ftp->dir($remotedirname) or errormessage("Can\'t get listing
> > of $remotedirname - $!\n");
> > &messageprint ("OK\n");
> > foreach (@lines)
> > {
> >   if (substr ($_,0,1) eq "-")                       # download files
> >   {
> >     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
> >     $filesize=sprintf "%d",$1;                      # get file size
> >     $filename=&getfilename($');                     # get file name
> > (trunc after date)
> >  print "$filename ($filesize)\n";
> >
> >   }
> > }
> >
> > $ftp->quit;
> > print "END.\n";
> >
> > #### Second Attempt ##################################################
> > # Firewall access information
> > $firewallname="ftpgate.somewhere.com";
> > $firewalluser="abcuser";
> > $firewallpassword="userpassword";
> >
> > # FTP Server address, login and password
> > $ftpname="ftp2.SomeOtherPlace.com";
> > $ftpusersite='userxyz@ftp2.SomeOtherPlace.com';
> > $loginname="userxyz";
> > $password='userxyzpassword';
> >
> > # Connect to firewall
> > print "Connecting to $firewallname...";
> > $ftp=Net::FTP->new ($firewallname, Debug => 1) or errormessage("Can\'t
> > connect to Firewall $firewallname\n");
> > print "OK\n";
> >
> > # Login to firewall
> > print "Login to firewall as $loginname...";
> > $ftp->login($firewalluser,$firewallpassword) or errormessage("Can\'t
> > login as $firewalluser/$firewallpassword- $!\n");
> > print "OK\n";
> >
> > # Login to ftp site
> > print "Follow on Login as $ftpusersite...";
> > $ftp->command("user $ftpusersite") or errormessage("Can\'t do second
> > login as user $ftpusersite - $!\n");
> > print "OK\n";
> > $ftp->command($password) or errormessage("Can\'t do second login
> > password as $password - $!\n");
> > print "OK\n";
> >
> > #### Complete whatever you will be doing on ftp server. i.e. get put
> > etc. ####
> > &messageprint ("Get directory listing of $remotedirname...");
> > my @lines=$ftp->dir($remotedirname) or errormessage("Can\'t get listing
> > of $remotedirname - $!\n");
> > &messageprint ("OK\n");
> > foreach (@lines)
> > {
> >   if (substr ($_,0,1) eq "-")                       # download files
> >   {
> >     $filesize=substr($_,30)=~/(\d+\.?\d*|\.\d+)/;   # get file size
> >     $filesize=sprintf "%d",$1;                      # get file size
> >     $filename=&getfilename($');                     # get file name
> > (trunc after date)
> >  print "$filename ($filesize)\n";
> >
> >   }
> > }
> >
> > $ftp->quit;
> > print "END.\n";
> >
> > Thank You
> > Don (needs to learn perl more DOH!) Lundgren
> > dlungren@corecomm.net
>
> --
> Terrence Brannon
> Oracle Corporation
> 500 Oracle Parkway
> M/S 3op1556a
> Redwood Shores, CA 94065
> (650) 607-5482



------------------------------

Date: Wed, 4 Apr 2001 18:40:49 +0000 (UTC)
From: bob_waltenspiel@agilent.com
Subject: Using perlembed.pod code?
Message-Id: <986418650.437426@cswreg.cos.agilent.com>

I'm enhancing an existing C++ program to do pattern matching from a
data file.  The data file will contain both the pattern and the data.
I simply want a boolean reponse if there is a match. 

Perl is the first choice for this task.  I would like to embed perl
into my program following the examples in perlembed.pod.

Using the sample code match.c from perlembed.pod seems to be exactly
what I want but I having trouble compiling it.  It's not finding the
definitions for three functions:

g++ -I/opt/perl5/lib/5.00503/PA-RISC1.1/CORE -L/opt/perl5/lib/5.00503/PA-RISC1.1/CORE -o match match.c -lperl -lm
match.c: In function `struct sv * my_eval_sv(struct sv *, long int)':
match.c:17: warning: implicit declaration of function `int eval_sv(...)'
match.c: In function `long int substitute(struct sv **, char *)':
match.c:82: warning: implicit declaration of function `int get_sv(...)'
match.c:82: warning: assignment to `sv *' from `int' lacks a cast
match.c: In function `long int matches(struct sv *, char *, struct av **)':
match.c:111: warning: implicit declaration of function `int get_av(...)'
match.c:111: warning: assignment to `av *' from `int' lacks a cast
collect2: ld returned 1 exit status
/usr/ccs/bin/ld: Unsatisfied symbols:
   get_av (code)
   get_sv (code)
   eval_sv (code)
*** Error code 1

Using the tips from the pod file, I have tried all the suggestions for
finding these functions but to no avail.  Can anyone help me?


-Bob

-- 
 Bob Waltenspiel
 Agilent Technologies          | e-mail: bob_waltenspiel@agilent.com
 Santa Rosa, California  USA   | phone: (707) 577-3091



------------------------------

Date: Wed, 04 Apr 2001 13:06:50 -0700
From: Gary W <gary@db.stanford.edu>
Subject: What level of Perl needed for my system() call to work?
Message-Id: <3ACB7EDA.906ABB9A@db.stanford.edu>

I build a command in my Perl script and do system($cmd) or exec($cmd).
The socket connection requested by my program is refused.
When I cut and paste it (from the Perl print of $cmd) to
the shell it connects ok.
$cmd contains the port number as a program arg.

It seems to be ok in 5.6, but not 5.005.
Does anyone know when the pertinent change was,
so I can put in a require?


-- 

Gary Wesley
Stanford       
"Life without music would be a mistake." F. Nietzsche


------------------------------

Date: 04 Apr 2001 15:09:52 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: What level of Perl needed for my system() call to work?
Message-Id: <m3vgokfmun.fsf@dhcp9-175.support.tivoli.com>

On Wed, 04 Apr 2001, gary@db.stanford.edu wrote:

> I build a command in my Perl script and do system($cmd) or
> exec($cmd).  The socket connection requested by my program is
> refused.  When I cut and paste it (from the Perl print of $cmd) to
> the shell it connects ok.  $cmd contains the port number as a
> program arg.
> 
> It seems to be ok in 5.6, but not 5.005.
> Does anyone know when the pertinent change was,
> so I can put in a require?

Without knowing what's in $cmd, it's hard to guess what might be the
problem, but I'll try anyway....

Perhaps there is something in $cmd that is getting parsed incorrectly
when handed off to the shell (or maybe even before that).

OK -- that isn't much of a guess... let's see the value of $cmd....

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Wed, 04 Apr 2001 13:50:16 -0700
From: Gary W <gary@db.stanford.edu>
Subject: Re: What level of Perl needed for my system() call to work?
Message-Id: <3ACB8908.282CBAA8@db.stanford.edu>

Ren,

From the console:

Connecting on 171.64.75.93:9613 issuing command: 
 ../handlers/process net://Eh:9613 90000000 > /dev/null 
at Wed Apr  4 09:54:41 2001

(There is no carriage return in the actual command)

thanks and hookem horns,
Gary (1982 UT grad)

 Maddox wrote:
> 
> On Wed, 04 Apr 2001, gary@db.stanford.edu wrote:
> 
> > I build a command in my Perl script and do system($cmd) or
> > exec($cmd).  The socket connection requested by my program is
> > refused.  When I cut and paste it (from the Perl print of $cmd) to
> > the shell it connects ok.  $cmd contains the port number as a
> > program arg.
> >
> > It seems to be ok in 5.6, but not 5.005.
> > Does anyone know when the pertinent change was,
> > so I can put in a require?
> 
> Without knowing what's in $cmd, it's hard to guess what might be the
> problem, but I'll try anyway....
> 
> Perhaps there is something in $cmd that is getting parsed incorrectly
> when handed off to the shell (or maybe even before that).
> 
> OK -- that isn't much of a guess... let's see the value of $cmd....
> 
> --
> Ren Maddox
> ren@tivoli.com

-- 

Gary Wesley
Stanford       
"Life without music would be a mistake." F. Nietzsche


------------------------------

Date: Wed, 04 Apr 2001 18:19:55 GMT
From: dclxvi@best.com (Josh Geller)
Subject: Wrapper To Log Output Of Win32 cmd.exe
Message-Id: <fBJy6.3903$Up.151137@sea-read.news.verio.net>

Folks,

I have a perl script which runs fine when called under the WINNT
cmd.exe.

I want to snag the output of this and write it to a file.

To this end, I have written a tiny perl script which goes like this:

#!/usr/bin/perl -w

use strict;

&main;

sub main {

    my $cmd = "../../../WINNT/System32/cmd.exe \/c";
    $cmd =~ s/\r//g;
    my $perlscript = "..\\..\\Directory\\perlscript.pl";

    my $commandstring = "$cmd $perlscript";

    open(PIPE, "$commandstring |") || die "Could not open PIPE: $! \n";
    open(FILE, ">file.txt") || die "Could not open FILE: $! \n";

    while(<PIPE>) {
	print FILE $_;
    }
    close(PIPE);
    close(FILE);
}

This does not work! 

It dumps me out into the cmd prompt.

Does anyone have any ideas as to how I may accomplish this simple
task?

Thank you in advance.








------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 631
**************************************


home help back first fref pref prev next nref lref last post