[Answered ]-Using java code in the django framework

2👍

If I understand you correctly, you want to pipe the value of request.POST[‘post’] to the program run_pipeline.sh and store the output in a field of your instance.

  1. You are calling subprocess.Popen incorrectly. It should be:

    p = subprocess.Popen(['/path/to/run_pipeline.sh'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

  2. Then pass in the input and read the output

    (stdoutdata, stderrdata) = p.communicate()

  3. Then save the data, e.g. in a field of your instance

    instance.processed_data = stdoutdata
    instance.save()

I suggest you first make sure to get the call to the subprocess working in a Python shell and then integrate it in your Django app.

Please note that creating a (potentially long-running) subprocess in a request is really bad practice and can lead to a lot of problems. The best practice is to delegate long-running tasks in a job queue. For Django, Celery is probably most commonly used. There is a bit of setup involved, though.

Leave a comment