shell - p.stdout.read() empty when using python subprocess -


i try output of curl command using python subprocess. output empty. below source code:

def validateurl(url):     p = subprocess.popen("curl",                          stdin = subprocess.pipe,                          stdout = subprocess.pipe,                          stderr = subprocess.pipe,                          shell = false)     p.stdin.write("http://validator.w3.org/check?uri=" + url + "\n")     p.stdin.close()     stdout_data = p.stdout.read()     print stdout_data     result = re.findall("error", stdout_data)     print result # empty here     if (len(result) != 0):         return 'err'     else:         return 'ok' 

why? ps: run piece of code on mac os , use python 2.7.

drop stderr = subprocess.pipe,, , see error message printed curl. act accordingly fix it.

one possible reason url should specified command-line argument, , not on stdin:

p = subprocess.popen(("curl", "http://..."), stdout=subprocess.pipe) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -