Reputation: 63
I have designed a website using Flask (Python 2.7). I have sent a Python script (c.py
) to the client using the send_file()
function.
Now I want to run c.py
on the client system from the server side maybe by using my website itself or my system. Is there a possible way to do that?
Note: Client and server are on the same network.
Is it possible to write a python script which can run another python script on another system?
Upvotes: 0
Views: 4321
Reputation: 3490
exec("input the content of your py file"), which supports dynamic execution of Python code.
A demo here: Suppose that you could run Python script on client side
=== Server Side ===
from flask import Flask, send_file
import StringIO
app = Flask(__name__)
@app.route('/')
def index():
sio = StringIO.StringIO()
sio.write('print("hello world")')
sio.seek(0)
return send_file(sio, attachment_filename="c.py")
app.run(debug=True)
=== Client Side ===
import requests
code = requests.get('http://localhost:5000').text
exec(code) # <-----
Upvotes: 1