Python 3.x 在python3中使用子流程模块传输两个命令时遇到问题

Python 3.x 在python3中使用子流程模块传输两个命令时遇到问题,python-3.x,subprocess,Python 3.x,Subprocess,这就是我得到的。(我知道这很糟糕)它需要一个参数,即域名。对其运行subfinder,然后将结果写入结果 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_co

这就是我得到的。(我知道这很糟糕)它需要一个参数,即域名。对其运行subfinder,然后将结果写入结果

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]'])
现在,我只想看看是否可以打开该文件,将每一行导入一个新命令,然后再将其写入另一个文件。我把所有的东西都注释掉了,除了:

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)
返回:

b''
b''
b''
我怎样才能让它打印出结果?或者一个参考。此外,新的_文件目前只包含三行:

 domain.com
 another_domain.com
 non-existent.com

[解决]我想我会继续回答我自己的问题。经过几个小时的反复试验,终于找到了答案。这是我的解决方案

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]