Append to File Using Subprocess in Python -
how append file without opening using linux echo command? i've tried sort of possibilities unable achieve result. i'm not sure i'm missing.
documentation said type out exact command when shell set 'true' (yes security risk). echo command works when type in linux terminal not through subprocess. don't see "test.txt" 'this test string.'
>>> string = 'this test string.' >>> cmd = 'echo \"' + string + '\" >> test.txt' >>> cmd 'echo "this test string." >> test.txt' >>> >>> subprocess.check_call (cmd, shell = true) 0 >>> >>> subprocess.call (['echo', '\"', string, '\"', ' >> ', ' test.txt']) 0 >>>
you're passing redirector ">>" argument echo, it's not argument, it's part of shell. you'll need run shell string command. string what's in cmd variable. immediate option comes mind is:
subprocess.call(["sh", "-c", cmd]);
though i've used subprocess module, , may not best way want.
Comments
Post a Comment