1

Below is my code

view.py

from flask import render_template
#Import variables stored in _init_.py
from app import app

@app.route('/')
@app.route('/index')
def index():
import subprocess
memory = subprocess.Popen(['date'])
out,error = memory.communicate()

return render_template('view.html', out=out, error=error)

view.html

{{ out }}

It prints none, none, I am not sure what's wrong as it works fine in the python script

Update : Thanks for the answers, this is how you can do it

1
  • 2 notes - 1. why do use multiple annotations for your REST path 2. please explain "it works fine in my python script", which script ? Commented Dec 15, 2014 at 9:26

1 Answer 1

2

If you want to grab stdout from your command you need to add stdout=subprocess.PIPE as in:

memory = subprocess.Popen(['date'], stdout=subprocess.PIPE)
Sign up to request clarification or add additional context in comments.

2 Comments

Is this compulsory? As I was able to display the output of my command without the pipe in my python script, Also, along with the date, I get numbers I am not sure why,
If you want the output into a variable, yeah. If you don't specify it then it'll go out to the standard out channel, e.g. your command line if you run it as a standalone script.

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.