简体   繁体   中英

Can fabric run a local script on a remote machine?

I have myfile.py on my local machine.

I want to do something like:

from fabric.api import env, run

env.host_string = 'whatever.com'

def run_script():
    run('python myfile.py')

but of course, this returns can't open file 'myfile.py': [Errno 2] No such file or directory How can I run this file remotely? Do I have to put it onto whatever.com ?

You can first push your myfile.py to the remote machine using fabric.operations.put and then run the script like you've attempted to.

But make sure the path to your script is either an absolute path or relative to the current directory from which the remote commands are being executed, this can be found out using cwd you can also manually cd into the remote folder using fabric.context_managers.cd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM