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.
Documentation said to type out the exact command when shell is set to 'True' (Yes with security risk). 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.'
>>> string = 'This is a test string.'
>>> cmd = 'echo \"' + string + '\" >> test.txt'
>>> cmd
'echo "This is a test string." >> test.txt'
>>>
>>> subprocess.check_call (cmd, shell = True)
0
>>>
>>> subprocess.call (['echo', '\"', string, '\"', ' >> ', ' test.txt'])
0
>>>