Sponsored Content
Top Forums Shell Programming and Scripting calling perl subroutine from perl expect module Post 302485799 by arun_maffy on Thursday 6th of January 2011 08:28:09 AM
Old 01-06-2011
calling perl subroutine from perl expect module

All,

Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program.

Thanks,
Arun V
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Correct Syntax For Calling Shell Script in Perl Module

Problem: I have a shell script that will be called by a Perl module that will connect to a db and delete rows. The Perl module will be called by CRON. I am using a Perl module to call a shell script because I need to get the db connection from Perl. Here is the Perl pseudocode: ... (4 Replies)
Discussion started by: mh53j_fe
4 Replies

2. Shell Programming and Scripting

Replace Perl Module name in all Perl scripts

I want to replace a Perl module name in all my Perl Scripts in the cgi-bin directory. How is it possible? I have the following statement in my scripts use myUtil; I want to change it to use myUtil777; Regards, Rahul (2 Replies)
Discussion started by: rahulrathod
2 Replies

3. Shell Programming and Scripting

Calling Expect script in Perl...

I call a EXPECT script from my perl script with machine IP and a FIle. The script logins to the machine and exports the value. The values to be exported or stored in a file. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line, Now I could like... (4 Replies)
Discussion started by: ramkriz
4 Replies

4. Shell Programming and Scripting

Help with a perl subroutine regex

Hi, I can't get this script ot work and I wa wondering if anyone could help? I need to open a file and use a subroutine to search each line for a regular expression. If it matches then I need to return a match from the subroutine and print the result? Any help would be greatly... (11 Replies)
Discussion started by: jmd2004
11 Replies

5. Shell Programming and Scripting

Handling SQL prompt through Perl expect module

Hi All, I have a doubt whether expect module in perl will work in SQL prompt or its applicable only for shell prompt ? Thanks, Arun V (2 Replies)
Discussion started by: arun_maffy
2 Replies

6. Shell Programming and Scripting

Why Perl Subroutine Passed In Variable is 1?

The following subroutine prints 1 instead of the content of the Equipment variable. Can someone tell me why? #!c:/perl/bin/perl.exe # use strict 'vars'; my $Equipments = "data/equips.txt"; unless (open(EQUIP_FH, "$Equipments")) { print "errors: $Equipments\n"; # This line prints... (1 Reply)
Discussion started by: tqlam
1 Replies

7. Shell Programming and Scripting

Calling perl subroutine from shell script (sh)

Hi, ive a perl script, where it has a subroutine clear() in it, and i've one shell script which runs in background, from that shell script i wanted to call subroutine which is in perl script, that's perl script is not module, just simple script. Eg: perl script <test> #!... (4 Replies)
Discussion started by: asarunkumar
4 Replies

8. Programming

perl: Subroutine question

Hi everyone, I have given up finally trying to find a way to do this. I have a subroutine called LoginFirst where I am starting a new SSH session. I have bunch of subroutines, each one of them uses a (or I have to create a new SSH constructor everytime) ssh connection to get some value so ... (2 Replies)
Discussion started by: dummy_code
2 Replies

9. Shell Programming and Scripting

perl -Calling the Subroutine Only if the condition is met

Hello All, I am in the process of learning perl.I have a perl script and based on the arguments passed it would the appropriate subroutine that is defined in the script. Now, I need to check a value that is defined in the Environment variables and should call the subroutine only if the... (1 Reply)
Discussion started by: filter
1 Replies

10. Shell Programming and Scripting

PERL: Calling a sub routine from another module - help!!!

Hi, I am an occasional PERL user. I am trying to call a sub routine (passing parameters) in perl module from a driver .pl file. I have been "tinkering" for a while now and have confused myself. Could someone please look at the code below and spot where I am going wrong. testPerl.pl ... (0 Replies)
Discussion started by: chris01010
0 Replies
Test::Log4perl(3pm)					User Contributed Perl Documentation				       Test::Log4perl(3pm)

NAME
Test::Log4perl - test log4perl SYNOPSIS
use Test::More tests => 1; # setup l4p use Log::Log4Perl; # do your normal Log::Log4Perl setup here use Test::Log4perl; # get the loggers my $logger = Log::Log4perl->get_logger("Foo::Bar"); my $tlogger = Test::Log4perl->get_logger("Foo::Bar"); # test l4p Test::Log4perl->start(); # declare we're going to log something $tlogger->error("This is a test"); # log that something $logger->error("This is a test"); # test that those things matched Test::Log4perl->end("Test that that logs okay"); # we also have a simplified version: { my $foo = Test::Logger->expect(['foo.bar.quux', warn => qr/hello/ ]); # ... do something that should log 'hello' } # $foo goes out of scope; this triggers the test. DESCRIPTION
This module can be used to test that you're logging the right thing with Log::Log4perl. It checks that we get what, and only what, we expect logged by your code. The basic process is very simple. Within your test script you get one or more loggers from Test::Log4perl with the "get_logger" method just like you would with Log::Log4perl. You're going to use these loggers to declare what you think the code you're going to test should be logging. # declare a bunch of test loggers my $tlogger = Test::Log4perl->get_logger("Foo::Bar"); Then, for each test you want to do you need to start up the module. # start the test Test::Log4perl->start(); This diverts all subsequent attempts Log::Log4perl makes to log stuff and records them internally rather than passing them though to the Log4perl appenders as normal. You then need to declare with the loggers we created earlier what we hope Log4perl will be asked to log. This is the same syntax as Test::Log4perl uses, except if you want you can use regular expressions: $tlogger->debug("fish"); $tlogger->warn(qr/bar/); You then need to run your code that you're testing. # call some code that hopefully will call the log4perl methods # 'debug' with "fish" and 'warn' with something that contains 'bar' some_code(); We finally need to tell Test::Log4Perl that we're done and it should do the comparisons. # start the test Test::Log4perl->end("test name"); Methods get_logger($category) Returns a new instance of Test::Logger that can be used to log expected messages in the category passed. Test::Logger->expect(['dotted.path', 'warn' => qr'this', 'warn' => qr'that'], ..) Class convenience method. Used like this: { # start local scope my $foo = Test::Logger->expect(['foo.bar.quux', warn => qr/hello/ ]); # ... do something that should log 'hello' } # $foo goes out of scope; this triggers the test. start Class method. Start logging. When you call this method it temporarly redirects all logging from the standard logging locations to the internal logging routine until end is called. Takes parameters to change the behavior of this (and only this) test. See below. debug(@what) info(@what) warn(@what) error(@what) fatal(@what) Instance methods. String of things that you're expecting to log, at the level you're expecting them, in what class. end() end($name) Ends the test and compares what we've got with what we expected. Switches logging back from being captured to going to wherever it was originally directed in the config. Ignoring All Logging Messages Sometimes you're going to be testing something that generates a load of spurious log messages that you simply want to ignore without testing their contents, but you don't want to have to reconfigure your log file. The simpliest way to do this is to do: use Test::Log4perl; Test::Log4perl->suppress_logging; All logging functions stop working. Do not alter the Logging classes (for example, by changing the config file and use Log4perl's "init_and_watch" functionality) after this call has been made. This function will be effectivly a no-op if the enviromental variable "NO_SUPRESS_LOGGING" is set to a true value (so if your code is behaving weirdly you can turn all the logging back on from the command line without changing any of the code) Selectivly Ignoring Logging Messages By Priority It's a bad idea to completely ignore all messages. What you probably want to do is ignore some of the trivial messages that you don't care about, and just test that there aren't any unexpected messages of a set priority. You can temporarly ignore any logging messages that are made by passing parameters to the "start" routine # for this test, just ignore DEBUG, INFO, and WARN Test::Log4perl->start( ignore_priority => "warn" ); # you can use the levels constants to do the same thing use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $WARN ); You might want to ignore all logging events at all (this can be used as quick way to not test the actual log messages, but just ignore the output. # for this test, ignore everything Test::Log4perl->start( ignore_priority => "everything" ); # contary to readability, the same thing (try not to write this) use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $OFF ); Or you might want to not ignore anything (which is the default, unless you've played with the method calls mentioned below:) # for this test, ignore nothing Test::Log4perl->start( ignore_priority => "nothing" ); # contary to readability, the same thing (try not to write this) use Log::Log4perl qw(:levels); Test::Log4perl->start( ignore_priority => $ALL ); You can also perminatly effect what things are ignored with the "ignore_priority" method call. This persists between tests and isn't autoically reset after each call to "start". # ignore DEBUG, INFO and WARN for all future tests Test::Log4perl->ignore_priority("warn"); # you can use the levels constants to do the same thing use Log::Log4perl qw(:levels); Test::Log4perl->ignore_priority($WARN); # ignore everything (no log messages will be logged) Test::Log4perl->ignore_priority("everything"); # ignore nothing (messages will be logged reguardless of priority) Test::Log4perl->ignore_priority("nothing"); Obviously, you may temporarly override whatever perminant BUGS
Logging methods don't return the number of appenders they've written to (or rather, they do, as it's always zero.) Changing the config file (if you're watching it) while this is testing / supressing everything will probably break everything. As will creating new appenders, etc... AUTHOR
Mark Fowler <mark@twoshortplanks.com> COPYRIGHT
Copyright 2005 Fotango Ltd all rights reserved. Licensed under the same terms as Perl itself. perl v5.14.2 2011-11-16 Test::Log4perl(3pm)
All times are GMT -4. The time now is 12:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy