Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comm.pl Help

by NateTut (Deacon)
on Jan 15, 2009 at 22:47 UTC ( [id://736701]=perlquestion: print w/replies, xml ) Need Help??

NateTut has asked for the wisdom of the Perl Monks concerning the following question:

I'm on a Solaris box running Perl 5.6.1, I can't upgrade it and I can only use pure perl modules since our Unix admins in their infinite wisdom decided not to install a C compiler. And this is the government so forget about asking for any changes.

Which is why I'm using Comm.pl instead of Expect.pm or something more modern. I modified an example from the bottom of Comm.pl.

Update: Sorry I removed some extraneous code before posting but after executing. The output now reflects the code as shown.

Here's the code with the problem:

use strict; use warnings; $| = 1; require 'Comm.pl'; use IPC::Open3 qw/open3/; &Comm::init(1.8); my $TimeOut = 30; my $Server = 'Server'; my $User = 'User'; my $Password = 'Password'; my ( $Proc_pty_handle, $Proc_tty_handle, $pid ) = &open_proc( "bteq"); die "open_proc failed" unless $Proc_pty_handle; my ($success, $matched, $before_match, $after_match) = &expect($Proc_p +ty_handle, $TimeOut, 'Enter your logon or BTEQ command:'); die("Time out\n") unless ($success); print(" \$matched \[$matched\] \$before_match\[$before_match\] \$success \[$success\] \$after_match \[$after_match \] "); print $Proc_pty_handle ".logon $Server/$User\n";

Here's the output:

$matched [] $before_match[ Teradata BTEQ 08.02.04.00 for UNIX5. Copyright 1984-2006, NCR Corporation. ALL RIGHTS RESERVED. ] $success [Enter your logon or BTEQ command:] $after_match [ ] Can't use string ("proccommutils000001") as a symbol ref while "strict + refs" in use at btp.pl line 25.

I've not a clue what is going on here. This is my first attempt at any kind of an expect type app which might be part of the problem.

Thanks.

Replies are listed 'Best First'.
Re: Comm.pl Help
by gone2015 (Deacon) on Jan 16, 2009 at 01:11 UTC

    The problem is that Comm.pl is ancient history.

    Comm::open_proc() has created a glob proccommutils000001 in the calling package, and that is the file handle. It has returned the string "proccommutils000001" which has been assigned to $Proc_pty_handle. This is what used to be known as an "indirect filehandle".

    Unfortunately, with "strict refs" in effect you can not use an indirect filehandle. Current open documentation warns you about that.

    You could turn off strict 'refs' wherever you want to use the $Proc_pty_handle. Or you can construct a ref to the glob whose name is in $Proc_pty_handle, and that is an OK filehandle ! The following illustrates what's going on:

    use strict ; use warnings ; my $handle = oldstyle('FHOO') ; print FHOO "Open Worked !\n" ; print FHOO "Yes indeed !\n" ; { no strict 'refs' ; print $handle "Via \$handle, but no strict 'refs'\n" ; } ; my $FH ; { no strict 'refs' ; $FH = \*{$handle} ; } ; print $FH "Now via \$FH, with strict 'refs'\n" ; print $handle "Will throw error under strict 'refs'\n" ; sub oldstyle { my ($indirect_handle) = @_ ; # $indirect_handle contains nam +e of handle to open on { no strict 'refs' ; open $indirect_handle, '>&1' ; } ; return $indirect_handle ; } ;
    and gives:
    Open Worked !
    Yes indeed !
    Via $handle, but no strict 'refs'
    Now via $FH, with strict 'refs'
    Can't use string ("FHOO") as a symbol ref while "strict refs" in use at shakerattleandhum.pl line 25.
    
    where $handle above is equivalent to what is returned into $Proc_pty_handle.

    Updated to put back the use strict ; use warnings ; that had somehow gone walkabout -- one of those slips between cup and lip we hear so much about....

      Thanks!
Re: Comm.pl Help
by ikegami (Patriarch) on Jan 15, 2009 at 23:08 UTC

    Your script doesn't have 64 lines. Please post the code that matches the output or the output from the code you posted.

Re: Comm.pl Help
by sgt (Deacon) on Jan 16, 2009 at 18:04 UTC

    Just a comment.

    There is always the option to compile what you need on a similar machine, and package that, taking care (on exec) of external and generated shared libraries with the appropriate setting of LD_DYNAMIC_PATH or similar.

    PAR and/or PAR::Packer could help also

    cheers --stephan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://736701]
Approved by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found