title: Best way to pipe the output of a local() to the stdin of a remote run() command in Fabric?
body: <p>Is there a simple way to pipe output from local commands to remote ones (and vice versa)?</p>
  
  <p>I've always just piped to a file, moved the file over, and then read it...but it seems like there could be an easier way.</p>
  
  <p>For simpler situations, just capturing the output and using string interpolation works:</p>
  
  <pre><code>ip = local('hostname -i')
  run('Script was run from ip: %s' % ip)
  </code></pre>
  
  <p>But when the output either needs escaping to be safe on the command line and/or needs to come from stdin it is a bit trickier.</p>
  
  <p>If the output is bash-safe, then something like <code>run('echo "%s" | mycmd' % ip)</code> would do what I'm looking for (which I guess implies that an equivalent question would be "is there a simple way to bash-escape strings?"), but it seems like there should be a "right way" to provide a remote stdin.</p>
  
  <p>Edit:</p>
  
  <p>To clarify with long-ish inputs there a number of potential problems with simple string interpollation: classic shell problems (eg. the output could contain <code>"; rm -rf /</code>) but also (and more realistically, in my case) the output can contain quotes (both single and double).</p>
  
  <p>I <em>think</em> just doing <code>run("echo '%s' | cmd" % output.replace("'", "'\\''")</code> should work, but there may be edge cases that misses.</p>
  
  <p>As I mentioned above, this seems like the type of thing that fabric could handle more elegantly for me by directly sending a string to the run()'s stdin (though perhaps I've just been spoiled by it handling everything else so elegantly :)</p>