This is little PERL function that is stored in the file gco.pl
and can be included into any PERL plugin to perform basic operation needed during interaction with remote host. It will send command to remote host, collect command output into PERL variable (for further processing, if needed) and wait for the remote host to respond with "expected" prompt at the end of the command output.
This function encapsulates all heavy details of direct handling of the STDIN/STDOUT/STDERR byte pipes (those pipes are connecting terminal window I/O streams and PLUGIN process I/O streams). Unfortunately, PERL STDIN/STDOUT/STDERR stream handles are not implemented as simple global variables, so for the use inside of the subroutines, they have to be passed by reference from the main program. That adds more arguments to the function call. User does not have to work with those handles directly but still have to pass them to the subroutine on every call.
This function can be seen as some sort of very simple open-source PERL-to-TERMINAL glue
interface library that is by itself written in PERL and helps programmer to control terminal easily from PERL programs. User can modify this function directly to fine tune its behavior. For example, very peculiar behavior of the remote equipment can be worked around as shown here.
To be able to use this function in any PERL plugin simply add following line in the beginning of the plugin code:
require "./plug/perl/gco.pl";
This line is assuming that .
in path to gco.pl file is referring to Proxy32 startup directory (which is made current directory for any plugin process). Before including this line, please, download file gco.pl
and place it into subdirectory plug/perl
inside of the proxy32 startup directory.
If the file gco.pl
is present in referred location, then user can use gco
function (in the PLUGIN code after require
statement) to query Oracle DB server via interactive Oracle SQLPLUS client in the following fashion:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
or instead of using perl one-liner, one can put the perl script into the plugin.pl
file and populate PLUGIN command line as follows:
perl ./plug/perl/plugin.pl
where file ./plug/perl/plugin.pl
would contain following lines:
1 2 3 4 5 6 7 8 9 10 |
|
As can be seen from the above example:
gco
takes references to I/O handles from main PERL program in first 3 arguments.Expected
remote host command prompt (that will signify the end of the command printout and readiness of the remote host to accept new command) is passed in 5th argument as PERL REGEX (with REGEX, not all characters are matching themselves, some needs to be escaped with \
, for example, \]
would match ]
as the prompt expected on exit from SQLPLUS),#
sign on user screen instead of showing actual command output)To download gco.pl
file click here.
Below is syntax-colored and line-numbered code of the gco
function.
expected
prompt (line 34). Cycle ends when expected
prompt is found.\x00
and \x0D
from collected command output.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|