Is there an easy way to output output from local commands to remote (and vice versa)?
I always just loaded into the file, moved the file and read it ... but it seems like it could be easier.
For simpler situations, just grab the output and use string interpolation:
ip = local('hostname -i') run('Script was run from ip: %s' % ip)
But when the output either needs to be escaped in order to be safe on the command line, and / or must come from stdin, it is a bit more complicated.
If the output of bash is -safe, then something like run('echo "%s" | mycmd' % ip) will do what I am looking for (which I think implies the equivalent question would be "there is a simple bash way - escape strings? "), but it looks like there must be a" correct path "to provide the remote stdin.
Edit:
To clarify using long-necked inputs, there are a number of potential problems with simple string interpolation: classic shell problems (for example, the output may contain "; rm -rf / ), but also (and more realistically, in my case) the output may contain quotation marks ( both single and double).
I think just executing run("echo '%s' | cmd" % output.replace("'", "'\\''") should work, but there may be cases of edges that are skipped.
As I mentioned above, this looks like the type of thing that the fabric can handle more elegantly for me by directly sending the string to run () stdin (although maybe I was just spoiled by the fact that it handled everything else so beautifully :)
source share