I would like to call system shell in a Python code and write the results in a text file. When I write this command:
call(["ls", "-lrt"])
The calling process works and print the files and folders list as an output on the screen. However, when I try to write the printed output in a text file (rather than screen), it does not work! I tried all these:
call(["ls", "-lrt", ">", "result.txt"])
call(["ls", "-lrt", "> result.txt"])
call(["ls -lrt > result.txt"])
But in the Linux shell this command "ls -lrt > result.txt
" nicely works.
I am using Linux CentOS 7 and my Python version is 2.7.5.
I will be thankful if anyone can help me for this simple problem.