Skip to main content
added 292 characters in body
Source Link
blhsing
  • 109.2k
  • 9
  • 88
  • 132

This is because your testprocess.communicate() for the wc -l command already consumes all of the output of userdataprocess.stdout and closes it in fact, so there's nothing left for dnslineprocess.communicate() to read.

You should instead read the output of userdataprocess.stdout into a variable and then use it as an input to both testprocess.communicate() and dnslineprocess.communicate():.

Also, as @pyb pointed out, you are unnecessarily quoting DNS= in your grep command, which, without a shell, will be passed to grep with double quotes included as part of the string to filter with. You should simply remove them as there are no special characters in your filter string.

import subprocess user = "testuser" getuserdata = 'cat /var/cpanel/users/' + user getdnsline = 'grep "DNS="'DNS=' test = 'wc -l' userdataprocess = subprocess.Popen(getuserdata.split(), stdout=subprocess.PIPE) userdata = userdataprocess.stdout.read() testprocess = subprocess.Popen(test.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) test, error = testprocess.communicate(userdata) print(test) dnslineprocess = subprocess.Popen(getdnsline.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) website, error = dnslineprocess.communicate(userdata) print(website.decode('utf-8').splitlines()) 

This is because your testprocess.communicate() for the wc -l command already consumes all of the output of userdataprocess.stdout and closes it in fact, so there's nothing left for dnslineprocess.communicate() to read.

You should instead read the output of userdataprocess.stdout into a variable and then use it as an input to both testprocess.communicate() and dnslineprocess.communicate():

import subprocess user = "testuser" getuserdata = 'cat /var/cpanel/users/' + user getdnsline = 'grep "DNS="' test = 'wc -l' userdataprocess = subprocess.Popen(getuserdata.split(), stdout=subprocess.PIPE) userdata = userdataprocess.stdout.read() testprocess = subprocess.Popen(test.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) test, error = testprocess.communicate(userdata) print(test) dnslineprocess = subprocess.Popen(getdnsline.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) website, error = dnslineprocess.communicate(userdata) print(website.decode('utf-8').splitlines()) 

This is because your testprocess.communicate() for the wc -l command already consumes all of the output of userdataprocess.stdout and closes it in fact, so there's nothing left for dnslineprocess.communicate() to read.

You should instead read the output of userdataprocess.stdout into a variable and then use it as an input to both testprocess.communicate() and dnslineprocess.communicate().

Also, as @pyb pointed out, you are unnecessarily quoting DNS= in your grep command, which, without a shell, will be passed to grep with double quotes included as part of the string to filter with. You should simply remove them as there are no special characters in your filter string.

import subprocess user = "testuser" getuserdata = 'cat /var/cpanel/users/' + user getdnsline = 'grep DNS=' test = 'wc -l' userdataprocess = subprocess.Popen(getuserdata.split(), stdout=subprocess.PIPE) userdata = userdataprocess.stdout.read() testprocess = subprocess.Popen(test.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) test, error = testprocess.communicate(userdata) print(test) dnslineprocess = subprocess.Popen(getdnsline.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) website, error = dnslineprocess.communicate(userdata) print(website.decode('utf-8').splitlines()) 
Source Link
blhsing
  • 109.2k
  • 9
  • 88
  • 132

This is because your testprocess.communicate() for the wc -l command already consumes all of the output of userdataprocess.stdout and closes it in fact, so there's nothing left for dnslineprocess.communicate() to read.

You should instead read the output of userdataprocess.stdout into a variable and then use it as an input to both testprocess.communicate() and dnslineprocess.communicate():

import subprocess user = "testuser" getuserdata = 'cat /var/cpanel/users/' + user getdnsline = 'grep "DNS="' test = 'wc -l' userdataprocess = subprocess.Popen(getuserdata.split(), stdout=subprocess.PIPE) userdata = userdataprocess.stdout.read() testprocess = subprocess.Popen(test.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) test, error = testprocess.communicate(userdata) print(test) dnslineprocess = subprocess.Popen(getdnsline.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) website, error = dnslineprocess.communicate(userdata) print(website.decode('utf-8').splitlines())