title: Mutt in bash script raises an error in python (flask) application
body: <p>I believe that the main problem here is with mutt command:
  <code>mutt -s "Title" -a $file -- "$address" &lt; $DIR/message.txt</code>.
  If I delete it from the script, there is no error so maybe someone will find out what is going on.</p>
  
  <p>This is a python application using flask. Here is the problematic method:</p>
  
  <pre><code>@app.route('/send', methods=['POST'])
  def send():
  start_date = '2016-10-20'
  end_date = '2016-10-28'
  path = os.path.dirname(os.path.realpath(__file__))
  script = path + '/script.sh'
  address = 'my@mail.com'
  subprocess.check_call([script, start_date, end_date, address])
  return json.dumps({
      'message': 'Your message is sent!'
  })
  </code></pre>
  
  <p>Subprocess runs script : </p>
  
  <pre><code>#!/bin/bash
  start_date="$1"
  end_date="$2"
  address="$3"
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd )"
  $file="My_super_file"
  out=$(R -e "rmarkdown::render('$DIR/generate_file.Rmd', output_file = $file)")
  mutt -s "Title" -a $file -- "$address" &lt; $DIR/message.txt
  </code></pre>
  
  <p>When the file is generated, I get such error:</p>
  
  <pre><code>[2016-10-28 16:03:06,857] ERROR in app: Exception on /send [POST]
  Traceback (most recent call last):
    File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
      response = self.full_dispatch_request()
    File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
      rv = self.dispatch_request()
    File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "Users/admin/mydemoapp/app/appdemo/views.py", line 18, in send
      subprocess.check_call([script, start_date, end_date, address])
    File "/Users/admin/anaconda2/lib/python2.7/subprocess.py", line 541, in check_call
      raise CalledProcessError(retcode, cmd)
  CalledProcessError: Command '['/Users/admin/mydemoapp/app/appdemo/script.sh', '2016-10-20', '2016-10-28', u'my@mail.com']' returned non-zero exit status 1
  </code></pre>