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

It sounds like you logged into another system using expect features in a PERL program on the current system. If you want to run some PERL on the remote system, you have to call PERL there and provide it with scripting either from a file there or pushed down the pipe from the first system/script. That is two main PERL scripts running on two systems, with a login pipeline between them.

Hi DGPickett,

Yes, you got that exactly. How to implement the second method you mentioned, like running 2 main programs with a login pipe. I don't want to run a separate perl script on the remote machine because of 2 reasons:

  1. The remote perl script is not available before hand because the content of the script is different every time I run.
  2. There need not be an extra file in the remote system if it is possible to include in the current script only.

Thanks for your help,
Arun V

Well, if you know there is a usable PERL on the other end, you can run it and send the source down the pipe. Remember that PERL is an interpreted system.

Sorry, but can you please be more detailed,as I'm not well versed with PERL terms.

Thanks again,

PERL draws input from the keyboard, a file, or a library references in a file, but it is all pretty much the same to PERL. Whatever PERL commands you want to run, that code can all be sent down the pipe as keyboard input to a remote PERL invocation, or you can send files down the pipe to /tmp and get PERL to take input from them. If you are using PERL libraries, it is a bit messy figuring how to turn them into one stream, and they may call additional libraries. Maybe PERL has a facility like CC -E or cpp, where all the includes are turned into one file.

Of course, it what you want to achieve on the far end an be reduced to the minimum, it makes it simpler. You can solicit a flow of data from the remote system using a few commands to a simple shell or PERL invocation there, and process it on the original system in the driving PERL script there. It is a classic choice of function shipping or data shipping. If there is too much remote data, then function shipping makes sense.

The perl expect script is just a media in place of something more script friendly like rcp/scp/scp2rsh/ssh/ssh2 passwordless access. What it runs on the far end is a completely divorced discussion, as well as what it feeds locally. There is not normally any expectation that a PERL expect script calls PERL modules. Trying to achieve more than access may just complicate the expect function. Usually, it is better to write something else to run locally and remotely to solve the problem, and the perl expect is just a building block to get the remote access necessary for the other local and remote code to solve the problem.

1 Like