A more generic script for testing cli commands:

Code:
--------------------
    
  #!/usr/bin/perl -w
  # perl script to send commands to SqueezeCenter via the cli
  # uses code from Max Spicer's shutdown.pl
  
  use strict;
  use IO::Socket;
  use POSIX qw(strftime);
  
  # Print debug output if true.  Higher values increase verbosity.
  my $debug = 0;
  
  my $argument = shift;
  
  
  # Change server details below if necessary
  my $socket = IO::Socket::INET->new (PeerAddr => '127.0.0.1',
  PeerPort => 9090,
  Proto    => 'tcp',
  Type     => SOCK_STREAM)
  or die 'Couldn\'t connect to server';
  
  
  print "Sending \'$argument\' to the cli...\n";
  my $return = sendAndReceive($argument);
  
  print "\'$argument\' returned \'$return\'\n";
  
  close $socket;
  
  # Send given cmd to $socket and return answer with original command removed 
from
  # front if present.  Routine nicked from code by Felix Mueller. :-)
  sub sendAndReceive {
  my $cmd = shift;
  
  return if( $cmd eq "");
  
  print $socket "$cmd\n";
  $debug > 1 && print "Sent $cmd to server\n";
  my $answer = <$socket>;
  $debug > 1 && print "Server replied: $answer\n";
  $answer =~ s/$cmd //i;
  $answer =~ s/\n//;
  
  return $answer;
  }
  
--------------------

On my system:
[EMAIL PROTECTED] sbin]# cli.pl 'player count ?'
Sending 'player count ?' to the cli...
'player count ?' returned '3'
[EMAIL PROTECTED] sbin]#


-- 
gharris999
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=40610

_______________________________________________
beta mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/beta

Reply via email to