Store value of os.system or os.popen
Posted
by chrissygormley
on Stack Overflow
See other posts from Stack Overflow
or by chrissygormley
Published on 2010-05-12T09:20:32Z
Indexed on
2010/05/12
9:24 UTC
Read the original article
Hit count: 481
Hello,
I want to grep the error's out of a log file and save the value as an error. When I use:
errors = os.system("cat log.txt | grep 'ERROR' | wc -l")
I get the return code that the command worked or not. When I use:
errors = os.popen("cat log.txt | grep 'ERROR' | wc -l")
I get what the command is trying to do.
When I run this in the command line I get 3 as thats how many errors there are.
Can anyone suggest another way?
Thanks
© Stack Overflow or respective owner