Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取python变量中的wget输出_Python_Wget_Openwrt - Fatal编程技术网

获取python变量中的wget输出

获取python变量中的wget输出,python,wget,openwrt,Python,Wget,Openwrt,我可以使用wget下载该文件,并且可以在控制台中看到进度,但是如何将该输出存储到python变量中呢 下面给出了一个示例代码,类似这样的东西我是例外 output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf') 我不建议使用wget,而是使用urllib: 如果必须使用wget,只需在wget写入输出文件后读取它即可 os.system('wget https://www.tutori

我可以使用wget下载该文件,并且可以在控制台中看到进度,但是如何将该输出存储到python变量中呢

下面给出了一个示例代码,类似这样的东西我是例外

output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf')

我不建议使用wget,而是使用urllib:

如果必须使用wget,只需在wget写入输出文件后读取它即可

os.system('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf -O your_file_path')
print open('your_file_path').read()

通常,您可以通过子进程捕获程序的标准输出

import subprocess

output = subprocess.check_output('ping localhost', stderr=subprocess.STDOUT, shell=True)

@Peter Wood可能重复,wget结果与其他操作系统命令不同results@Arun在链接副本上