[英]How do I fix my function to store the data?
My function runs URLcrazy and I figured out it is not storing the output into any variables and I cannot figure it out. 我的函数运行URLcrazy,我发现它没有将输出存储到任何变量中,因此我无法弄清楚。 The tmp variable shown is not storing the output into that list.
显示的tmp变量未将输出存储到该列表中。 How I can fix this to store the data executed.
我如何解决此问题以存储执行的数据。
def run_urlcrazy():
tmp = []
for domain in grab_domains():
np = os.system("urlcrazy " + domain)
tmp.append(np)
return tmp
I am trying to get the output of URLcrazy ran against all the domains in the loop and be able to slice the ouptut. 我试图让URLcrazy的输出针对循环中的所有域运行,并能够切片ouptut。 I think the way URLcrazy is outputting data I am unable to format the data in another function.
我认为URLcrazy输出数据的方式无法在其他函数中格式化数据。 Which I need to be able to do in order to store information in a database.
我需要能够将信息存储在数据库中。
os.system
does not return the output of the command executed, only the exit code (signals success or error). os.system
不返回执行该命令,仅退出代码(信号成功或错误)的输出。
I believe you want subprocess.Popen
: 我相信你想要
subprocess.Popen
:
import subprocess
def run_urlcrazy():
tmp = []
for domain in grab_domains():
proc = subprocess.Popen(["urlcrazy", domain], stdout=subprocess.PIPE)
(out, err) = proc.communicate()
tmp.append(out)
return tmp
Alternatively, you can use subprocess.check_output
if you just want the output and are not interested in checking for errors: 另外,如果您只需要输出并且不希望检查错误,则可以使用
subprocess.check_output
:
out = subprocess.check_output(['urlcrazy', domain])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.