Perl Telnet Issue - Igv Automation
1
0
Entering edit mode
10.9 years ago
GANI ▴ 230

In the following PERL code, I am invoking a java based application (IGV) in Windows 7 and then communicating with this application using telnet (Net::Telnet).

The application returns message "OK", if any command is successfully executed. I used this message as the prompt in "cmd" function of Net::Telnet.

The first command (setSleepInterval) and the second command runs (snapshotDirectory) well, and after that the communication stalls till timeout. The second command successfully sends the message "OK", but some how the control is not transferred to the next statement.

The commands "snapshotDirectory" and "load" are mutually exclusive. So when I interchanged those two commands, the "load" runs successfully and then communication stalls till timeout.

I have no success even when I used the combination of "print" and "waitfor" functions of the module Net::Telnet.

#!/usr/bin/perl
use strict;
use warnings;

use Net::Telnet;
use Data::Dumper;

system("igv_mm.jnlp"); #Invoke the java application
sleep(10);
my ($i, @geneList, $sessionDir, $sleeptime, $promptMatch, $prom);
$sessionDir = "session-file-location";
$sleeptime = 500;
$promptMatch = '/^(OK)/';

my $telnet = ();
$telnet = Net::Telnet->new( Timeout => 120,
            Host => 'localhost',
            Port => 60151
                          );
if( $telnet ){
    #$telnet->telnetmode(0);
    print "connected to the IGV port\n";
    $telnet->dump_log(\*STDOUT);
    $telnet->output_log("out.log");
    $telnet->input_log("in.log");
$telnet->cmd(String => 'setSleepInterval '.$sleeptime, Prompt  => $promptMatch);
$telnet->cmd(String => 'snapshotDirectory '.$sessionDir.'\\igv_figures', Prompt  => $promptMatch);
$telnet->cmd(String => 'load '.$sessionDir.'\\igv_session.xml', Prompt  => $promptMatch);
$telnet->cmd(String => 'exit');
}
else {
    print "failed to connect";
}

$telnet->close;

Let me know if you have any suggestions. Thanks in advance.

igv perl windows • 4.0k views
ADD COMMENT
1
Entering edit mode
10.9 years ago
Michael 55k

Why do you think you can control IGV via telnet? According to the documention of IGV you can control it via Sockets, there is an example code in Java there. The corresponding module in Perl is IO::Socket. You could try to translate the Java example to Perl.

edit:

Note: IGV will write a response back to the port socket upon completion of each command. It is good practice to read this response before sending the next command. Failure to do so can overflow the socket buffer and cause IGV to freeze. See the example below for the recommended pattern.

Does your code do that (I guess cmd does it)? If not that would explain why the timeout occurs after any 2 invocations.

Is the prompt always correct as 'OK' for all invocations of cmd or does any command return a different prompt where the prompt regex doesn't match?

What is the output of each invocation?

What happens if you run this command sequence via telnet directly from the console?

ADD COMMENT
0
Entering edit mode

I saw the feature that controls IGV from a specific port and thought of trying it. I dont think it matters whether the communication is through telnet or socket. Also, I was able to successfully communicate through telnet. I think this is more of an issue with the perl module Net::Telnet. Thanks for the information about the pre-existing Java code. I will check it out.

ADD REPLY
0
Entering edit mode

I think that the people at stackoverflow will know more about these network programming tasks which are a bit off for a bioinformatics site (e.g. difference between sockets and telnet, windows oddities). Could you try the example Java code directly first and then test if the commands work? See my edit also.

ADD REPLY

Login before adding your answer.

Traffic: 2079 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6