0

having a difficult time understanding how to get python to call a system function...

the_file = ('logs/consolidated.log.gz')         
webstuff = subprocess.Popen(['/usr/bin/zgrep', '/meatsauce/', the_file ],stdout=subprocess.PIPE) % dpt_search
    for line in webstuff.stdout:
        print line

Trying to get python to build another file with my search string.

Thanks!

5
  • I have no clue how you intend what you wrote to work... Commented Jun 21, 2011 at 21:20
  • :) in perl, you would write system or qx ("/usr/bin/zgrep blah filename > output"); Commented Jun 21, 2011 at 21:23
  • 1
    You have a % in there. That is not where % could go, much less where it would go. Commented Jun 21, 2011 at 21:23
  • 1
    Running a subprocess and parsing its output != system call Commented Jun 21, 2011 at 22:38
  • possible duplicate of python subprocess.Popen Commented Jun 22, 2011 at 11:08

1 Answer 1

1

I recommend the PyMotW Subprocess page from Doug Hellmann who (quoted) "Reads the docs so you don't have to"

Apart from that:

f = file('sourcefile')
for line in f:
    if 'pattern' in line:
            # mind the , at the end,
            # since there's no stripping involved
            # and print adds a newline without it
            print line, 

if you need to match regular expressions apart from the documentation in the Python Standard Library documentation for the re module also refer to the PyMotW Regular Expression page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.