Why doesn't this subprocess.call module grep the result?

16 Views Asked by At

I'm trying to grep a specific header, but this code doesn't do grep. Lets say I want to grep the header "Content-Type:" so the program should only print the line which contains "Content-Type:".

#!/usr/bin/env python3

import subprocess
import optparse

parser = optparse.OptionParser()
parser.add_option("-u", "--url", dest="url", help="Add the URL.")
parser.add_option("-s", "--string", dest="strinj", help="The string you want to grep")
(options, arguments) = parser.parse_args()

url = options.url
strinj = options.strinj
subprocess.call(["curl", "-s", "-I", url, "|", "grep", "-i", strinj])

What if I want to hard code "Content-Type" in the code (with the semi colon), Is it enough to replace it with the "strinj"?

0

There are 0 best solutions below