I have a script file (.py) which I need to run in my POST API requests. The scripts have few input parameters as well.
I am able to follow the link: https://django-extensions.readthedocs.io/en/latest/runscript.html and now I am successfully able to run a script from the shell.
python manage.py runscript scriptName --script-args arg1 arg2
But now, I want to run the same script with arguments in my API where arguments will be posted from the POST requests. I found that I can use subprocess for it. But it's not working.
Below is the code I am trying to run:
cmd = subprocess.Popen(['scriptName', arg1, arg2], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = cmd.communicate()
On executing the above code the script file opens up in the browser.
NOTE: The script which I am executing contains Machine Learning Code.
Please help me out and let me know what I am doing wrong here. I also need the output of the script to return as a response.