title: Use socat to connect to socket, send a command, and read a single line
body: <p>I have a process which can be communicated with via a UNIX socket (actually an <a href="http://man7.org/linux/man-pages/man7/unix.7.html"><strong>abstract socket</strong></a> which I think is Linux-specific).</p>
  
  <p>I'm writing a shell script which needs to send commands to this process.  I decided to try using SOCAT for this purpose.  I'm trying to figure out how to (1) connect to the abstract socket, (2) send it a single command (a string), (3) read the response and print the response to stdout.</p>
  
  <p>So far, I can connect easily by simply saying:</p>
  
  <pre><code>socat ABSTRACT-CONNECT:mysocket STDIN
  </code></pre>
  
  <p>This connects STDIN to the socket, so if I know manually type a command, the socket will read in the string, and then output the resulting response to the console.</p>
  
  <p>Except when I run socat in a script, I need to automate sending a string to STDIN.  Okay, so the most straightforward way to do this seemed to be to just pipe a string to STDIN.  So suppose we have a command called "<code>status</code>", I would say:</p>
  
  <pre><code>echo status | socat ABSTRACT-CONNECT:mysocket STDIN
  </code></pre>
  
  <p>This seems to work (socat reports no errors), except the result is not sent to stdout.  Rather, the call simply returns with no response.  So how can I also read a single line from the socket and display the result on stdout?</p>