python - Best way to pipe the output of a local() to the stdin of a remote run() command in Fabric? -


is there simple way pipe output local commands remote ones (and vice versa)?

i've piped file, moved file over, , read it...but seems there easier way.

for simpler situations, capturing output , using string interpolation works:

ip = local('hostname -i') run('script run ip: %s' % ip) 

but when output either needs escaping safe on command line and/or needs come stdin bit trickier.

if output bash-safe, run('echo "%s" | mycmd' % ip) i'm looking (which guess implies equivalent question "is there simple way bash-escape strings?"), seems there should "right way" provide remote stdin.

edit:

to clarify long-ish inputs there number of potential problems simple string interpollation: classic shell problems (eg. output contain "; rm -rf /) (and more realistically, in case) output can contain quotes (both single , double).

i think doing run("echo '%s' | cmd" % output.replace("'", "'\\''") should work, there may edge cases misses.

as mentioned above, seems type of thing fabric handle more elegantly me directly sending string run()'s stdin (though perhaps i've been spoiled handling else elegantly :)

you send remote stdin fexpect, fabric extension. sends file, hides behind api. still have escaping though.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -