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.
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.
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.