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

Dear Experts.

I am utilising the Net::Telnet module in order to access a remote terminal to make an SQL query into a database.

As suggested within the documentation, I am utilising the cmd() command to interact with terminal. This command is recommended to read data into an array from the terminal (see code below).

# # SQL Query to execute # $cmd = "select * from table A"; # # Wait for prompt - ">>" at terminal # $t->prompt('/\>\>\s*$/'); # # Send SQL Query to terminal # $t->cmd($cmd); # # Debug # print "cmd 1 = $cmd<p><p>" if $debug; # # Execute SQL command # $cmd = "go"; # # Wait for prompt - "(1)>>" # $t->prompt('/\(\1\)\>\>\s*$/'); # # Read in data from terminal to array # @lines = $t->cmd($cmd); # # Debug # print "prompt_string = $prompt_string<p>" if $debug; print "lines = $t->cmd($cmd)<p>" if $debug; print "lines array = @lines<p>" if $debug; print "cmd 2 = $cmd<p>" if $debug;
The debug generated is as follows:
cmd 1 = select * from table A lines = Net::Telnet=<edited>->cmd(go) lines array = cmd 2 = go NoLines = 0
The code appears to compile correctly, however, when attempting to debug out the @lines array, I get a blank. I have also attempted to convert @lines to a scalar value to check how many lines it contains and this yields a 0.

It appears that for some reason, the @lines array has not been populated. Could anyone suggest a reason as to how to overcome this problem?

(I have manually queried the database with the SQL query which results in a 2 column/1 row table)

Thanks in advance...

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: CMD Command
by Abigail-II (Bishop) on Sep 09, 2003 at 10:49 UTC
    # # Wait for prompt - "(1)>>" # $t->prompt('/\(\1\)\>\>\s*$/');

    That comment doesn't match the code. You are too eager in your backwacking. Try:

    $t -> prompt ('/[(]1[)]>>\s*$/');

    I don't know whether that will fix your problem, but it's a start.

    Abigail

Re: CMD Command
by NetWallah (Canon) on Sep 09, 2003 at 16:21 UTC
    You can (and probably should) use the diagnostic features provided by Net::Telnet.

    • $t->Input_log('File-Name_to_Log.txt');
    • $t->errmsg and die "ERROR: $t->errmsg\n"; # After each cmd