0

I'm playing around with building a MPD client for my private use and came across the following problem.

I need to (from a /bin/sh script):

  1. send a command over tcp to the sever
  2. wait for an OK on a line of its own
  3. send a close command to the server to clean up the connection

Is there any command line tool I can use to do this (I could code it in C/Java/Python but would prefer not to introduce the dependency)

I have tried netcat but am unable to do step 2, which leads to me losing parts of the response from 1 as the connection is closed before the output is sent.

What I tried that did not work all the time was.

printf 'command_list_ok_begin\nnext\nstatus\nplaylistinfo\ncommand_list_end\nclose\n'|nc -w 5 $mpdhost 6600 # 
lijat
  • 640
  • 7
  • 16
  • What shell are you actually using? POSIX shell has no socket capabilities, so you already have an external dependency on a non-standard tool (`netcat`), so you might as well switch to another language. If you can assume a specific shell like `bash` or `zsh`, then there are options available for communicating via TCP in the shell itself. – chepner Apr 24 '17 at 14:57
  • Without changing the enviroment it is dash – lijat Apr 24 '17 at 16:18

0 Answers0