0

I can run this command cat /home/norman/conf/second.txt | sort | uniq > /home/norman/conf/third.txt but would like to use an os,system call or a subprocess call but whatever I have tried always causes an error. I have tried such things as command = "cat /home/norman/conf/second.txt | sort | uniq > /home/norman/conf/third.txt".split() subprocess.call(command) but get

cat: '|': No such file or directory cat: sort: No such file or directory cat: '|': No such file or directory cat: uniq: No such file or directory cat: '>': No such file or directory

Buteman
  • 53
  • 8
  • Take a look at this question too: https://stackoverflow.com/q/21029154/510937 – Bakuriu Jan 27 '18 at 10:33
  • Sorry it doesn't seem to be a duplicate to me. I want to send stdout to a file not display it on the screen so I can use it to do further processing of the data. In any case I have found out how to do it now. – Buteman Jan 27 '18 at 13:40
  • This exact problem can be done even simpler in actual Python code: `with open('/home/norman/conf/second.txt', 'r') as f: result = sorted(set(f))`. – Daniel Pryden Jan 27 '18 at 13:46
  • @Buteman Just redirect `stdout` to an open file object by assigning `stdout=my_file` (open the file as `with open(, 'w') as my_file`. – Bakuriu Jan 29 '18 at 19:14

0 Answers0