Having trouble piping two commands using subprocess module with python3

Viewed 39

So here's what I got. ( It's terrible I know) It takes one argument, which is name of domain. Runs subfinder on that, then writes result's to results.

def getSubs(command):
    result = subprocess.check_output(command, shell=True, universal_newlines=True)
    with open('results', 'w') as file_contents:
        for i in result:
            file_contents.write(i)
    http_check()

getSubs(['subfinder -d' 'sys.argv[1]'])

For now I just want to see If I can open up the file to pipe each line into a new command and worry about writing it to a another file later. I commented out everything except:

def httpCheck():
    with open('results', 'r') as file_to_iterate:
        for scan in file_to_iterate:
            p1 = subprocess.Popen([f"echo", "{scan}"], stdout=subprocess.PIPE)
            p2 = subprocess.Popen(['httprobe'], stdin=p1.stdout, shell=True, stdout=subprocess.PIPE)
            p1.stdout.close()
            output = p2.communicate()[0]
            print(output)

Which returns:

b''
b''
b''

How can I get it to print out the results? Or a reference. Also the new_file just contains three lines for now:

 domain.com
 another_domain.com
 non-existent.com
1 Answers

[ SOLVED ] I guess I'll go ahead and answer my own question. Finally figured it out after hours of trial and error. This is my solution.

def httpCheck():
    with open('new_file', 'rb') as file_to_iterate:
        for scan in file_to_iterate:
            with open('results.txt', 'a') as f:
                p1 = subprocess.Popen(["echo", scan], stdout=subprocess.PIPE)
                p2 = subprocess.Popen(['httprobe', '-t', '1000'], stdin=p1.stdout, stdout=f)
                output = p2.communicate()[0]
Related