title: Append to File Using Subprocess in Python
body: <p>How do I append to a file without opening it using Linux echo command?  I've tried all sort of possibilities but unable to achieve the result.  I'm not sure what I'm missing.</p>
  
  <p>Documentation said to type out the exact command when shell is set to 'True' <em>(Yes with security risk)</em>.  The echo command works when I type it in Linux terminal but not through subprocess.  I don't see the "test.txt" with 'This is a test string.'</p>
  
  <pre><code>&gt;&gt;&gt; string = 'This is a test string.'    
  &gt;&gt;&gt; cmd = 'echo \"' + string + '\" &gt;&gt; test.txt'
  &gt;&gt;&gt; cmd
  'echo "This is a test string." &gt;&gt; test.txt'
  &gt;&gt;&gt; 
  &gt;&gt;&gt; subprocess.check_call (cmd, shell = True)
  0
  &gt;&gt;&gt; 
  &gt;&gt;&gt; subprocess.call (['echo', '\"', string, '\"', ' &gt;&gt; ', ' test.txt'])
  0
  &gt;&gt;&gt; 
  </code></pre>