0

I am trying to get the following python code to work, I am just not able to get the syntax to work. Can someone assist?

import subprocess
import shlex

subprocess.call(shlex.split('top -d 5 -n 1 -b -o %CPU | head -n 12 > output.txt'))
Jay Webster
  • 179
  • 1
  • 3
  • 12

1 Answers1

0

I got the below to work, Thanks for help!

import subprocess

subprocess.Popen("top -d 5 -n 1 -b -o %CPU | head -n 12 > output.txt",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
Jay Webster
  • 179
  • 1
  • 3
  • 12