0

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?

4
  • maybe you should better design your program in such way: en.wikipedia.org/wiki/Remote_procedure_call ? Commented Dec 26, 2017 at 11:00
  • There are couple ways to do it. One easy way is through SSH (if running on Linux/Mac platform) Commented Dec 26, 2017 at 11:06
  • @py_dude thanks will look into it. Commented Dec 26, 2017 at 11:22
  • My server operates on windows. So I need help on that. @Vinny 16 Commented Dec 26, 2017 at 11:23

1 Answer 1

1

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)  # <-----
Sign up to request clarification or add additional context in comments.

3 Comments

How and where to use this?
When your client system receive c.py, pass the content of c.py into exec
I added a demo. But I do not know how your client looks like, so suppose that you could run Python script on client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.