0
import os 
cmd='for file in /proc/*/status ; do awk \'/VmSwap/||/^Pid/||/Name/{printf "%-20s", $2 $3}END{ print""}\' $file; done | sort -nr -k 3  | head -5'
os.system(cmd)

output, i have added # , my question is , why am i getting broken pipe error , last two lines.

>>> res = os.system(cmd)

sort: write failed: standard output: Broken pipe

sort: write error

shankar
  • 431
  • 7
  • 13
  • Use `subprocess.check_output(cmd, shell=True)` or better yet just do it in pure python, there is nothing in your cmd that python cannot do – Padraic Cunningham Jan 26 '16 at 09:41
  • @pardraic , I directing output of different command to a file and using subprocess to write to single file makes difficult due to creation of child process and each child process tries to write to the file at the same time affecting the sequence in which that has to be written . please see if you can do with os.system . – shankar Jan 26 '16 at 09:56
  • does adding `| dd obs=1M` before `| head -n 5` work? – Padraic Cunningham Jan 26 '16 at 10:09
  • @Padraic. I will use subprocess and store the results in some temp file and later I will add them . dd obs=1M didn't work . – shankar Jan 26 '16 at 11:09
  • It works for me, what OS are you using? Why don't you just redirect stdout to a file? – Padraic Cunningham Jan 26 '16 at 11:11

0 Answers0