On 12/06/2015 4:45 PM, AMARASINGHAM, Chandra wrote:

I was wondering if anyone had any ideas on how I can send a string of python code to a remote python interpreter using fabric?

I have successfully done this using something like the following, but I don't quite like using the -c flag and would like to send the script as stdin if possible. The use case is a local Linux server and a remote AIX server both running python 2.7.


The main page for python says you can just use - for the filename for stdin. But:

$ python -

seems to go straight to the interactive interpreter.

However

$ cat - | python -

definitely works straight from stdin, as if it was reading a python file.

This all seems like a bit of a hack, but the following fabfile.py seems to work for me:

-------

import fabric
from fabric.api import run

pycode = """

# code to be run on remove server(s)

import os
print os.listdir('.')

"""

cmd = """python - << EOF
{pycode}
EOF""".format(pycode=pycode)

def runpycode():
    run(cmd)

-------

Adjust pycode to whatever you want.

Cheers,

Rasjid.



_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to