Taking the results of a bash command and using it in python,os.system('top -d 30 | grep %d > test.txt' % pid)